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.


You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.