Output of C programs | Set 41 - GeeksforGeeks

23 Aug, 2017
QUE.1 What will be output if you will compile and execute the following c code?
#include <stdio.h>int main(){    int a = 5;    float b;    printf("%d ", sizeof(++a + b));    printf("%d ", a);    return 0;}
(a)2 6(b)4 6(c)2 5(d)4 5
Answer : d
Explanation:
 ++a +b = 6 + Garbage floating point number
 = Garbage floating point number
// From the rule of automatic type conversion 
Hence 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;}
(a)5 garbage garbage(b)5 0 0(c)5 null null(d)Compiler error(e)None of above
Answer : b
Explanation: 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;}
(a)17(b)18(c)21(d)22(e)Compiler error
Answer : e
Explanation: 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;}
OPTION(a)5 10(b)6 11(c)5 11(d)6 10(e)Compiler error
Answer : c
Explanation: 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, thenwe 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: c 
Explanation: 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.
This article is contributed by Ajay Puri(ajay0007). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
C-Output
Program Output
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Output of C++ programs | Set 34 (File Handling)
Result of sizeof operator
Program to reverse columns in given 2D Array (Matrix)
Output of C++ Program | Set 1
Output of Java program | Set 26
Output of C++ programs | Set 22
unsigned specifier (%u) in C with Examples
Output of C Programs | Set 7
Output of C Programs | Set 6
Output of C programs | Set 8