C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Point Out Correct Statements (Q.No. 3)
3.
Which of the following statements are correct about the program?
#include<stdio.h>
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
Explanation:

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.

Discussion:
8 comments Page 1 of 1.

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.

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.

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

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

NESTED IF ELSE statement should be terminated with ELSE statement.

Correct it if I'm wrong.

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

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

Traian said:   4 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?

Post your comments here:

Your comments will be displayed after verification.