Error: 'else' without a previous 'if' in C
This error: 'else' without a previous 'if' is occurred when you use else statement after terminating if statement i.e. if statement is terminated by semicolon.
if...else statements have their own block and thus these statement do not terminate.
Consider the given code:
Output
How to fix?
See the statement, if(a==10);
Here, if statement is terminated by semicolon (;). Thus, Error: 'else' without a previous 'if' in C is occurred.
To fix the error remove the semicolon (;) after the if statement.
Correct code:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer