Output of C programs | Set 62 (Declaration & Initialization)

Prerequisite : Declaration & Initialization in C programming

Q1. Consider the following code:

What would be the output of the above code?
A. 2
B. 4
C. Would vary from complier to complier.
D. Error.

Output: D

Error: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int
Explanation:
Here, the compiler generates the error as extern int i is a declaration and not a definition.

Q2. Consider the following code:

What would be the output of the above code?
A. Error.
B. 3.14
C. 0
D. 3

Output: A

Error: conflicting types for ‘fun’
Explanation: The error occurs because we have mixed the ANSI prototype with K & R style of function definition. When we use ANSI prototype for a function and pass a float to the function it is promoted to a double. When the function accepts the double into a float a type mismatch occurs hence the error.

Q3. Consider the following code:

What would be the output of the above code?
A. Garbage Value
B. 0 0.000000
C. Would vary from complier to complier.
D. Error.

Output: B
  0 0.000000

Explanation:
When an automatic structure is partially initialised, the remaining elememnts of the structure are initialised to 0.

Q4. Consider the following code:

What would be the output of the above code?
A. 5
B. 0
C. 1
D. 10

Output: C
  1

Explanation:
Since x<y turns out to be true it is replaced by 1. This 1 is then compared with 5. Since this condition also turns out to be true it is replaced by 1. This 1 is then assigned to i

Q5. Consider the following code:

What would be the output of the above code?
A. 1 2 3
B. pass fail atkt
C. 1 2 0
D. 0 1 2

Output: D
0 1 2

Explanation:
Enum elements always take values like 0, 1, 2, 3, …. etc

This article is contributed by Abhishek Sharma. 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

Recommended Posts:


    Article Tags :


    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.