belongs to collection: C Common Errors Programs
Error: Expected '}' before 'else' occurs, if closing scope curly brace of if statement is missing.
Consider the code:
#include <stdio.h> int main() { int a = 10; if(a == 10) { printf("Yes!\n"); else { printf("No!\n"); } return 0; }
Output
prog.cpp: In function ‘int main()’: prog.cpp:10:2: error: expected ‘}’ before ‘else’ else ^~~~
How to fix?
See the code, closing curly brace } is missing before else statement. To fix this error - close the if statement's scope properly.
Correct code:
#include <stdio.h> int main() { int a = 10; if(a == 10) { printf("Yes!\n"); } else { printf("No!\n"); } return 0; }
Yes!
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Consider the code:
Output
How to fix?
See the code, closing curly brace } is missing before else statement. To fix this error - close the if statement's scope properly.
Correct code:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer