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()
{
float z = 12.35, c = 10;
if( ++z -z)
c += z;
else
c -= z;
printf( "%f %f", z, c);
return 0;
}

 

  • A.The program will result in compile time error
  • B.The program will print 12.35 22.35
  • C.The program will print 13.35 22.35
  • D.The program will print 1.35 11.35

Answer: A

Correct answer: The program will result in compile time error

The statement is written c - = z; with a space between the two characters. C reads - and = as two separate tokens there, so the line parses as c - (= z), which is a syntax error. A compound assignment operator has to be written as one token: c -= z;.

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

Post your comment

Please log in or register to post a comment.