The macro function SQR(x)(x*x) calculate the square of the given number 'x'. (Eg: 102) Step 1: int a, b=3; Here the variable a, b are declared as an integer type and the variable b is initialized to 3. Step 2: a = SQR(b+2); becomes, => a = b+2 * b+2; Here SQR(x) is replaced by macro to x*x . => a = 3+2 * 3+2; => a = 3 + 6 + 2; => a = 11; Step 3: printf("%d
", a); It prints the value of variable 'a'. Hence the output of the program is 11
Q. No. :
3
Question :
What does the "auto" specifier do?
A :
It automatically initializes a variable to 0;
B :
It indicates that a variable's memory will automatically be preserved.
C :
It automatically increments the variable when used.
#include< stdio.h >
int sumdig(int);
int main()
{
int a, b;
a = sumdig(123);
b = sumdig(123);
printf("%d, %d
", a, b);
return 0;
}
int sumdig(int n)
{
int s, d;
if(n!=0)
{
d = n%10;
n = n/10;
s = d+sumdig(n);
}
else
return 0;
return s;
}
Step 1: x=y=z=1; here the variables x ,y, z are initialized to value '1'.
Step 2: z = ++x || ++y && ++z; becomes z = ( (++x) || (++y && ++z) ). Here ++x becomes 2. So there is no need to check the other side because ||(Logical OR) condition is satisfied.(z = (2 || ++y && ++z)). There is no need to process ++y && ++z. Hence it returns '1'. So the value of variable z is '1'
Step 3: printf("x=%d, y=%d, z=%d
", x, y, z); It prints "x=2, y=1, z=1". here x is increemented in previous step. y and z are not increemented.
Q. No. :
15
Question :
What is the output of the following program segment?
void max(int x, int y, int m)
{ if(x>5) m=x;
else m=y;}
int main()
{
int i=20, j=5, k=0;
max(i,j,k);
printf("%d",k);
}
While calling the function myFunc address of array is passed and it is incremented by 3. Hence Now the address is pointing to L and print onwards ie LLO
Q. No. :
21
Question :
Which one of the following functions is the correct choice for moving blocks of binary data that are of arbitrary size and position in memory?
A :
memcpy()
B :
memset()
C :
strncpy()
D :
memmove()
Answer: D
Q. No. :
22
Question :
Assuming a short is two bytes long, what will be printed by the above code?
It will not compile because not enough initializers are given.
B :
6
C :
12
D :
24
Answer: D
Q. No. :
23
Question :
What will the output?
int i = 4;
switch (i)
{
default:
;
case 3:
i += 5;
if ( i == 8)
{
i++;
if (i == 9) break;
i *= 2;
}
i -= 4;
break;
case 8:
i += 5;
break;
}
printf("i = %d
", i);
A :
i = 5
B :
i = 8
C :
i = 9
D :
i = 10
Answer: A
Q. No. :
24
Question :
The sample code above releases memory from a linked list. Which of the choices below accurately describes how it will work?
struct node *nPtr, *sPtr; /* pointers for a linked list. */
for (nPtr=sPtr; nPtr; nPtr=nPtr->next)
{
free(nPtr);
}
A :
It will work correctly since the for loop covers the entire list.
B :
It may fail since each node "nPtr" is freed before its next address can be accessed.
C :
In the for loop, the assignment "nPtr=nPtr->next" should be changed to "nPtr=nPtr.next".
D :
The loop will never end.
Answer: B
Q. No. :
25
Question :
What will be the output of the code snippet if compiler is considered to be 32 bit?
struct ptr
{
int a;
char b;
int *p;
union xy
{
int x;
char y;
};
}abc;
printf("%d",sizeof(abc));
The struct emp is mentioned in the prototype of the function modify() before declaring the structure.To solve this problem declare struct emp before the modify() prototype.
c is a character and 'a' is integer of ASCII value of a
Q. No. :
28
Question :
int a [8] = { 0, 1, 2, 3 };
The definition of a above explicitly initializes its first four elements. Which one of the following describes how the compiler treats the remaining four elements?
A :
Standard C defines this particular behavior as implementation-dependent. The compiler writer has the freedom to decide how the remaining elements will be handled.
B :
The remaining elements are initialized to zero(0)
C :
It is illegal to initialize only a portion of the array. Either the entire array must be initialized, or no part of it may be initialized
D :
As with an enum, the compiler assigns values to the remaining elements by counting up from the last explicitly initialized element. The final four elements will acquire the values 4, 5, 6, and 7, respectively.