Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program?

#include <stdio.h>
int main()
{
    int a = 300, b, c;
    if(a >= 400)
        b = 300;
    c = 200;
    printf("%d, %d, %d\n", a, b, c);
    return 0;
}

 

  • A.300, 300, 200
  • B.Garbage, 300, 200
  • C.300, Garbage, 200
  • D.300, 300, Garbage

Answer: C

Correct answer: 300, Garbage, 200

The condition \(300 \ge 400\) is false, so b = 300 never runs - and b, an uninitialised automatic variable, holds whatever was on the stack. c = 200 is a separate statement outside the if, so it always executes.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.