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

Discussion

Which of the following is an invalid if-else statement?

  • A.if (if (a == 1)){}
  • B.if (a){}
  • C.if ((char) a){}
  • D.if (func1 (a)){}

Answer: A

Correct answer: if (if (a == 1)){}

An if is a statement, and the parentheses of an if must contain an expression - so an if cannot appear there. The other three are fine: any scalar expression will do as a condition, including a cast and a function call.

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

Post your comment

Please log in or register to post a comment.