C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Point Out Correct Statements (Q.No. 3)
Which of the following statements are correct about the program?
int main()
    int x = 30, y = 40;
    if(x == y)
        printf("x is equal to y\n");

    else if(x > y)
        printf("x is greater than y\n");

    else if(x < y)
        printf("x is less than y\n")
    return 0;
Error: Statement missing
Error: Expression syntax
Error: Lvalue required
Error: Rvalue required
Answer: Option

This program will result in error "Statement missing ;"

printf("x is less than y\n") here ; should be added to the end of this statement.

8 comments Page 1 of 1.

Traian said:   5 years ago
The only error I get compiling this code is "Syntax error"-because of the missing semicolon.

Otherwise the program works and generates output, can anyone explain why? Is it because of the compiler or?

Harshit Shrivastava said:   1 decade ago
It will result in a compilation error stating "statement missing" as the semicolon is missing after the statement with the last else-if.

Swaty said:   1 decade ago
Shall we write a program using else-if ladder without using else statement? Anyone Please explain.

Thanks in advance.

Abhayraj SN said:   8 years ago
@Unknown. You are right.

NESTED IF ELSE statement should be terminated with ELSE statement.

Correct it if I'm wrong.

Chandramani said:   8 years ago
In this question, "semicolon" at the end of the "else if" statement is missing. Also "else" statement is missing.

Kamal said:   1 decade ago
Semi colon is required in the end of the statement it is missing so the statement missing error is coming.

Natasha said:   6 years ago
Aws per my knowledge, There is no else statement at last. Then how it is?

Unknown said:   9 years ago
Else statement also missing after else if.

Post your comments here:

Your comments will be displayed after verification.