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

Discussion

What is the output of this C code?    

void main()
    {
        int x = 97;
        int y = sizeof(x++);
        printf("x is %d", x);
    }

 

  • A.x is 97
  • B.x is 98
  • C.x is 99
  • D.Run time error

Answer: A

Correct answer: x is 97

sizeof is evaluated at compile time from the type of its operand, and its operand is not executed. So x++ never runs, y becomes sizeof(int), and x is still 97. (Variable-length arrays are the one exception where the operand is evaluated.)

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

Post your comment

Please log in or register to post a comment.