Which of the following is an invalid if-else statement? *
if (if (a == 1)){}
if (a){}
if ((char) a){}
if (func1 (a)){}
Answers
Answered by
29
Question ?
- Which of the following is an invalid if-else statement?
Answer:-
- if(if(a==1)){ } is an invalid if statement as we can't write if inside condition.
- if(a) {) is valid if a is a boolean literal else not.
- if((char)a) {} is invalid as there is no condition mentioned.
- if(func1(a)){} is valid if and only if return type of func1() is boolean.
Answered by
4
The First and the Third statements are invalid if-else statements.
For the first statement,
The use of an if statement inside another if statement is not allowed. It will result in an "invalid syntax type" error.
For the third statement,
In this statement, char is enclosed inside the braces and the identifier name is outside that. So this will again result in an "invalid syntax type" error.
For the second statement,
Passing any primitive data in the if condition statement results in true return.
For the fourth statement,
It is valid if the function returns anything back and that returning value will be considered as true.
Similar questions