It will not compile because not enough initializers are given.
B :
6
C :
12
D :
24
Answer: D
Q. No. :
2
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);
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
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. :
18
Question :
What is a proper method of opening a file for writing as binary file?
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.
Q. No. :
23
Question :
What number will z in the sample code below contain?
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. :
25
Question :
What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd> myprog 1 2 3
/* myprog.c */
#include< stdio.h >
#include
int main(int argc, char **argv)
{
int i, j=0;
for(i=0; i<argc; i++)
j = j+atoi(argv[i]);
printf("%d
", j);
return 0;
}
A :
123
B :
6
C :
Error
D :
"123"
Answer: B
Q. No. :
26
Question :
If an unsigned int is 2 bytes wide then, What will be the output of the program ?
#include< stdio.h >
int main()
{
unsigned int m = 32;
printf("%x
", ~m);
return 0;
}
A :
ffff
B :
0000
C :
ffdf
D :
ddfd
Answer: C
Q. No. :
27
Question :
What will be the output of the program?
#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;
}
A :
4,4
B :
3,3
C :
6,6
D :
12,12
Answer: C
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.