QUE.1 What will be output if you will compile and execute the following c code?
C
(a)2 6
(b)4 6
(c)2 5
(d)4 5
C
(a)5 garbage garbage
(b)5 0 0
(c)5 null null
(d)Compiler error
(e)None of above
C
(a)17
(b)18
(c)21
(d)22
(e)Compiler error
C
OPTION
(a)5 10
(b)6 11
(c)5 11
(d)6 10
(e)Compiler error
C
#include <stdio.h>
int main()
{
int a = 5;
float b;
printf("%d ", sizeof(++a + b));
printf("%d ", a);
return 0;
}
Answer : dExplanation:
++a +b = 6 + Garbage floating point number = Garbage floating point number // From the rule of automatic type conversionHence sizeof operator will return 4 because size of float data type in c is 4 byte. Value of any variable doesn’t modify inside sizeof operator. Hence value of variable a will remain 5. QUE.2 What will be output if you will compile and execute the following c code?
#include <stdio.h>
int main()
{
int array[3] = { 5 };
int i;
for (i = 0; i <= 2; i++)
printf("%d ", array[i]);
return 0;
}
Answer : bExplanation: Storage class of an array which initializes the element of the array at the time of declaration is static. Default initial value of static integer is zero. QUE.3 What will be output if you will compile and execute the following c code?
#include <stdio.h>
int main()
{
register int i, x;
scanf("%d", &i);
x = ++i + ++i + ++i;
printf("%d", x);
return 0;
}
Answer : eExplanation: In C, register variable stores in CPU it doesn’t store in RAM. So register variable do nor have any memory address. So it is illegal to write &a. QUE.4 What will be output if you will compile and execute the following c code?
#include <stdio.h>
int main()
{
int a = 5;
int b = 10;
{
int a = 2;
a++;
b++;
}
printf("%d %d", a, b);
return 0;
}
Answer : cExplanation: Default storage class of local variable is auto. Scope and visibility of auto variable is within the block in which it has declared. In C, if there are two variables of the same name, then we can access only local variable. Hence inside the inner block variable a is local variable which has declared and defined inside that block. When control comes out of the inner block local variable a became dead. QUE.5 What will be output if you will compile and execute the following C code?
#include <stdio.h>
int main()
{
float f = 3.4e39;
printf("%f", f);
return 0;
}
OPTION
(a)3.4e39
(b)3.40000…
(c)inf
(d)Compiler error
(e)Run time error
Answer: cExplanation: If you will assign value beyond the range of float data type to the float variable it will not show any compiler error. It will store infinity.