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

Discussion

Which of the following has compilation error in C ?

  • A.int n = 32 ;
  • B.char ch = 65 ;
  • C.float f = (float) 3.2 ;
  • D.none of the above

Answer: D

None of the declarations has a compilation error, so 'none of the above' is correct. int n = 32; is a plain initialisation. char ch = 65; is allowed because 65 fits in a char and is the code of 'A'. float f = (float) 3.2; is a valid cast from a double constant to float.

Each of the first three lines is therefore legal C, and no option other than the last can be the answer to a 'which has an error' question.

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

Post your comment

Please log in or register to post a comment.