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

Discussion

What is the output of this C code?

static int x;
    void main()
    {
        int x;
        printf("x is %d", x);
    }

 

  • A.Junk value
  • B.Run time error
  • C.Nothing

Answer: A

Correct answer: Junk value

The local int x; shadows the file-scope static, and being an automatic variable with no initialiser it holds whatever was on the stack - a junk value. Only variables with static storage duration are zeroed for you.

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

Post your comment

Please log in or register to post a comment.