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.
Answer: B
Q. No. :
4
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;
}
printf("%f
", sqrt(36.0)); It prints the square root of 36 in the float format(i.e 6.000000).
Declaration Syntax: double sqrt(double x) calculates and return the positive square root of the given number.
Q. No. :
6
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. :
7
Question :
Assume integer is 2 bytes wide. How many bytes will be allocated for the following code?
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.
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. :
22
Question :
What will print when the sample code below is executed?
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. :
23
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));
#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;
}
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. :
30
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;
}