If else statement in C++

Else statement:

An if statement can be followed by an optional else statement, which executes when the condition is false.
Syntax:

if(condition)
{
//statements
}
else
{
//statements
}

The compiler will test the condition:
:-If it evaluates to true, then the code inside the if statement will be executed
If it evaluates to false, then the code inside the else statement will be executed.
For examle:

int mark=90;
if(mark<33)
{
cout<<"You failed"<<endl;
}
else
{
cout<<You passed"<<endl;
}

Output:

You passed

**Note:-**When only one statement is used inside the if/else, then the curly braces can be omitted.



Related Article