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

Discussion

Which of the following statement is correct about the code snippet given below?

#include <stdio.h>
int main()
{
int n = 12, k;
printf("%d", (k = sizeof( n + 12.0))++);
return 0;
}

 

  • A.The code will print 17
  • B.The code will print 5
  • C.The code will result in a compile time error
  • D.The code will print 4

Answer: C

Correct answer: The code will result in a compile time error

(k = sizeof(n + 12.0))++ tries to increment the result of an assignment expression. That result is a value, not an object, so it is not a modifiable lvalue and the compiler rejects it. (Had the increment been dropped, sizeof(n + 12.0) would be 8 on a typical machine, since the int is promoted to double.)

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

Post your comment

Please log in or register to post a comment.