Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Output of C programs | Set 41

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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, 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: 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.


My Personal Notes arrow_drop_up
Last Updated : 23 Aug, 2017
Like Article
Save Article
Similar Reads