Escolar Documentos
Profissional Documentos
Cultura Documentos
1. What is C language?
The C programming language is a standardized programming language
developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on
the UNIX operating system. It has since spread to many other operating
systems, and is one of the most widely used programming languages. C is
prized for its efficiency, and is the most popular programming language for
writing system software, though it is also used for writing applications.
Variables with block scope, and with static specifier have static scope. Global
variables (i.e, file scope) with or without the the static specifier also have static
scope. Memory obtained from calls to malloc(), alloc() or realloc() belongs to
allocated storage class.
4. What is hashing?
To hash means to grind up, and that’s essentially what hashing is all about. The
heart of a hashing algorithm is a hash function that takes your nice, neat data
and grinds it into some random-looking integer.
The idea behind hashing is that some data either has no inherent ordering (such
as images) or is expensive to compare (such as images). If the data has no
inherent ordering, you can’t perform comparison searches.
13. Can you tell me how to check whether a linked list is circular?
Create two pointers, and set both to the start of the list. Update each as follows:
while (pointer1) {
pointer1 = pointer1->next;
pointer2 = pointer2->next;
if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print ("circular");
}
}
If a list is circular, at some point pointer2 will wrap around and be either at the
item just before pointer1, or the item before that. Either way, its either 1 or 2
jumps until they meet.
16. Write down the equivalent pointer expression for referring the same
element a[i][j][k][l] ?
a[i] == *(a+i)
a[i][j] == *(*(a+i)+j)
a[i][j][k] == *(*(*(a+i)+j)+k)
a[i][j][k][l] == *(*(*(*(a+i)+j)+k)+l)
17. Which bit wise operator is suitable for checking whether a particular
bit is on or off?
The bitwise AND operator. Here is an example:
enum {
KBit0 = 1,
KBit1,
…
KBit31,
};
if ( some_int & KBit24 )
printf ( “Bit number 24 is ON\n” );
else
printf ( “Bit number 24 is OFF\n” );
18. Which bit wise operator is suitable for turning off a particular bit in a
number?
The bitwise AND operator, again. In the following code snippet, the bit number
24 is reset to zero.
some_int = some_int & ~KBit24;
19. Which bit wise operator is suitable for putting on a particular bit in a
number?
The bitwise OR operator. In the following code snippet, the bit number 24 is
turned ON:
some_int = some_int | KBit24;
20. Does there exist any other function which can be used to convert an
integer or a float to a string?
Some implementations provide a nonstandard function called itoa(), which
converts an integer to string.
#include
char *itoa(int value, char *string, int radix);
DESCRIPTION
The itoa() function constructs a string representation of an integer.
PARAMETERS
value: Is the integer to be converted to string representation.
string: Points to the buffer that is to hold resulting string.
The resulting string may be as long as seventeen bytes.
radix: Is the base of the number; must be in the range 2 - 36.
A portable solution exists. One can use sprintf():
char s[SOME_CONST];
int i = 10;
float f = 10.20;
sprintf ( s, “%d %f\n”, i, f );
21. Why does malloc(0) return valid memory address ? What's the use?
malloc(0) does not return a non-NULL under every implementation. An
implementation is free to behave in a manner it finds suitable, if the allocation
size requested is zero. The implmentation may choose any of the following
actions:
* A null pointer is returned.
* The behavior is same as if a space of non-zero size was requested. In this case,
the usage of return value yields to undefined-behavior.
Notice, however, that if the implementation returns a non-NULL value for a
request of a zero-length space, a pointer to object of ZERO length is returned!
Think, how an object of zero size should be represented
For implementations that return non-NULL values, a typical usage is as follows:
void
func ( void )
{
int *p; /* p is a one-dimensional array, whose size will vary during the the
lifetime of the program */
size_t c;
p = malloc(0); /* initial allocation */
if (!p)
{
perror (”FAILURE” );
return;
}
/* … */
while (1)
{
c = (size_t) … ; /* Calculate allocation size */
p = realloc ( p, c * sizeof *p );
/* use p, or break from the loop */
/* … */
}
return;
}
Notice that this program is not portable, since an implementation is free to
return NULL for a malloc(0) request, as the C Standard does not support zero-
sized objects.
22. Difference between const char* p and char const* p
In const char* p, the character pointed by ‘p’ is constant, so u cant change the
value of character pointed by p but u can make ‘p’ refer to some other location.
In char const* p, the ptr ‘p’ is constant not the character referenced by it, so u
cant make ‘p’ to reference to any other location but u can change the value of
the char pointed by ‘p’.
1. Enabling startup application programs. Thus, the operating system must have:
- A text editor
- A translator
- An editor of links
A UNIQUE constraint is similar to PRIMARY key, but you can have more than
one UNIQUE constraint per table. Contrary to PRIMARY key UNIQUE
constraints can accept NULL but just once. If the constraint is defined in a
combination of fields, then every field can accept NULL and can have some
values on them, as long as the combination values is unique.
How can you sort the elements of the array in descending order?
Syntax
B = sort(A)
B = sort(A,dim)
B = sort(...,mode)
[B,IX] = sort(A,...)
Description
sort(A)
ans =5 6 10 23 45 78 100
What is DOM?
The Document Object Model (DOM) is a cross-platform and language-
independent convention for representing and interacting with objects in HTML,
XHTML and XML documents.[1] Objects in the DOM tree may be addressed
and manipulated by using methods on the objects. The public interface of a
DOM is specified in its application programming interface (API).
How macro execution is faster than function ?
Difference between overloading and overriding in programming language is:
. - dot operator
Sizeof() - operator
What is polymorphism?
In programming languages, polymorphism means that some code or operations
or objects behave differently in different contexts.
Typically, when the term polymorphism is used with C++, however, it refers to
using virtual methods, which we'll discuss shortly.
What are the differences between a C++ struct and C++ class?
The default member and base class access specifiers are different.
The C++ struct has all the features of the class. The only differences are that a
struct defaults to public member access and public base class inheritance, and a
class defaults to the private access specifier and private base class inheritance.
main()
{
char a[100], b[100];
printf("Enter the string to check if it is a palindrome\n");
gets(a);
strcpy(b,a);
strrev(b);
if( strcmp(a,b) == 0 )
printf("Entered string is a palindrome.\n");
else
printf("Entered string is not a palindrome.\n");
return 0;
}
Palindrome number in c
#include
main()
{
int n, reverse = 0, temp;
temp = n;
while( temp != 0 )
{
reverse = reverse * 10;
reverse = reverse + temp%10;
temp = temp/10;
}
if ( n == reverse )
printf("%d is a palindrome number.\n", n);
else
printf("%d is not a palindrome number.\n", n);
return 0;
}
Reverse a string using C programming
#include
#include
main()
{
char arr[100];
strrev(arr);
return 0;
}
#include
main()
{
int n, first = 0, second = 1, next, c;
return 0;
}
#include
int Fibonacci(int);
main()
{
int n, i = 0, c;
scanf("%d",&n);
printf("Fibonacci series\n");
return 0;
}
int Fibonacci(int n)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) + Fibonacci(n-2) );
}
Adding numbers in c using function
#include
main()
{
long first, second, sum;
printf("%ld\n", sum);
return 0;
}
result = a + b;
return result;
}
PART B
Choice :
a) Both are identical
b) The first is a correct declaration and the second is wrong
c) The first declaraion is a function returning a pointer to an integer and the
second is a pointer to function returning int
d) Both are different ways of declarin pointer to a function
Choice:
a) #2 = 2 b) expr=2 c) x/y=2 d) none
Answer: c)x/y=2
ans: The code functions properly releasing all the memory allocated
if(a=3)
b++;
printf("%d %d ",a,b++);
}
Answer : d) 3,7
Answer: d) NULL
main()
{
int l=6;
switch(l)
{ default : l+=2;
case 4: l=4;
case 5: l++;
break;
}
printf("%d",l);
}
a)8 b)6 c)5 d)4 e)none
Answer : c)5
Answer:d)10,22
struct Node {
char *word;
int count;
struct Node left;
struct Node right;
}
a) Incorrect definition
b) structures cannot refer to other structure
c) Structures can refer to themselves. Hence the statement is OK
d) Structures can refer to maximum of one other structure
Answer :c)
a)Hello,.World.
b).Hello,.Wor
c)Hello,.Wor..
d)None of the above
(1) The combined length of the longer two pieces of rope is 12 metres.
(2) The combined length of the shorter two pieces of rope is 11 metres.
10) A certain company paid bonuses of Rs. 125 to each of its executive
emplyees and Rs 75 to each of its nonexecutive employees. If 100 of the
employees were nonexecutive, how many were executive?
1) The company has a total of 120 employees
2) The total amount that the company paid in bonuses to its employees was
Rs.10,000
11. What fraction of his salary did Mr. Johnson put into savings last week ?
1) Last week Mr.Johnson put Rs 17 into savings.
2) Last week Mr.Johnson put 5% of his salary into savings.
12. Each M-type memory unit will increase the base memory capacity of
a certain computer by 3 megabytes. What is the base memory capacity,
in megabytes, of the computer ?
1) 2 M-type memory units will increase the computer's base memory capacity
by 300%
2) The memory capacity of the computer after 2-M type memory units
are added to the base memory capacity, is 1.6 times the memory capacity
of the computer after 1 M-type unit is added to the base memory capacity.
(A) (B) (C) (D) (E)
13. What fractional part of the total surface area of cube C is red?
1) Each of 3 faces of C is exactly 1/2 red
2) Each of 3 faces of C is entirely white
(A) (B) (C) (D) (E)
SECTION C
15. If taxi fares were Rs 1.00 for the first 1/5 mile and Rs 0.20 for each 1/5
miles thereafter. The taxi fare for a 3-mile ride was
(A)Rs 1.56 (B)Rs 2.40 (C)RS 3.00 (D)Rs 3.80 (E)Rs 4.20
16. A computer routine was developed to generate two numbers (x,y) the first
being a random number between 0 and 100 inclusive, and the second being less
than or equal to the square root of the first. Each of the following pair satisfies
the routine EXCEPT
(A) (99.10) (B) (85.9) (C) (50.7) (D) (1.1) (E) (1.0)
Answer : A) (99.10)
17. A warehouse had a square floor with area 10,000 sq.meters. A rectangular
addition was built along one entire side of the warehouse that increased
the floor by one-half as much as the original floor. How many meters did the
addition extend beyond the original buildings ?
(A)10 (B)20 (C)50 (D)200 (E)500
Answer: c)50
18. A digital wristwatch was set accurately at 8.30 a.m and then lost 2 seconds
every 5 minutes. What time was indicated on the watch at 6.30 p.m of the same
day if the watch operated continuously that time ?
(A)5:56 B)5:58 (C)6.00 (D)6.23 (E)6.26
19) A 5 litre jug contains 4 litres of a salt water solution that is 15 percent salt.
If 1.5 litres of the solution spills out of the jug, and the jug is then filled to
capacity with water, approximately what percent of the resulting solution in the
jug is salt?
Answer :A)7.5%
20) A plane travelled K miles in the first 96 miles of flight time. If it completed
the remaining 300 miles of the trip in 1 minute, what was its average speed in
miles per hour for the entire trip ?
(A)
(B)
(C)
(D)
(E)
Answer :(300+k)/97 * 60
21) A merchant sells an item at a 20 percent discount. but still makes a
gross profit of 20 percent of the cost. What percent of cost would be gross
profit on the item have been if it had been sold without the discount?
22) A millionaire bought a job lot of hats 1/4 of which were brown. The
millionaire sold 2/3 of the hats including 4/5 of the brown hats. What fraction
of the unsold hats were brown.
Answer :c)3/20
23) How many integers n greater than and less than 100 are there such that, if
the digits of n are reversed, the resulting integer is n+9 ?
Answer :D)8
Answer :B)50
25) At a special sale, 5 tickets can be purchased for the price of 3 tickets.
If 5 tickets are purchased at the sale, the amount saved will be what percent of
the original price of the 5 tickets?
Answer :c)40%
Answer :E)3
Answer :C) 5
SECTION III - ANALYSIS PROGRAM SEGMENTS
---------------------------------------
The first node's prev and the last node's next are NULL.
remove_element(dlink_t *rp)
{
rp->prev->next = rp->next;
rp->next->prev = rp->prev;
if( head == rp)
head = rp->next;
a) 4
b) 5
c) 6
d) 7
ans: a
04) On a machine where pointers are 4 bytes long, what happens when the
following code is executed.
main()
{
int x=0,*p=0;
x++; p++;
printf ("%d and %d ",x,p);
}
a) 1 and 1 is printed
b) 1 and 4 is printed
c) 4 and 4 is printed
d) causes an exception
05) Which of the following is the correct code for strcpy, that is used to copy
the contents from src to dest?
a) strcpy (char *dst,char *src)
{
while (*src)
*dst++ = *src++;
}
b) strcpy (char *dst,char *src)
{
while(*dst++ = *src++)
}
c) strcpy (char *dst,char *src)
{
while(*src)
{ *dst = *src;
dst++; src++;
}
}
d) strcpy(char *dst, char *src)
{
while(*++dst = *++src);
}
ans:b
6) Consider the following program
main()
{
int i=20,*j=&i;
f1(j);
*j+=10;
f2(j);
printf("%d and %d",i,*j);
}
f1(k)
int *k;
{
*k +=15;
}
f2(x)
int *x;
{
int m=*x,*n=&m;
*n += 10;
}