C Programming - Control Instructions - Discussion


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;

[A]. Error: Statement missing
[B]. Error: Expression syntax
[C]. Error: Lvalue required
[D]. Error: Rvalue required

Answer: Option A


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.

Kamal said: (Nov 15, 2011)  
Semi colon is required in the end of the statement it is missing so the statement missing error is coming.

Harshit Shrivastava said: (Feb 25, 2013)  
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: (Jun 8, 2013)  
Shall we write a program using else-if ladder without using else statement? Anyone Please explain.

Thanks in advance.

Unknown said: (Oct 25, 2015)  
Else statement also missing after else if.

Abhayraj Sn said: (Sep 1, 2016)  
@Unknown. You are right.

NESTED IF ELSE statement should be terminated with ELSE statement.

Correct it if I'm wrong.

Chandramani said: (Sep 7, 2016)  
In this question, "semicolon" at the end of the "else if" statement is missing. Also "else" statement is missing.

Natasha said: (Apr 24, 2018)  
Aws per my knowledge, There is no else statement at last. Then how it is?

Traian said: (Nov 17, 2019)  
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?

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.