Header Responsive Ads

If else Statement in C++

if else statement in c++

In the if statement, body code is executed only if the condition is true. However, no code is executed when the condition is false. For this C++ provides if-else C++ statement in which if the condition is false then code in else body is executed.

Syntax of if-else statement

if(condition)
{

if body code

}
else if(condition)
{

else-if body code

}
else
{

else body code

}      

Below a variable is declared and initialized with value 3. if-else 
statement condition check becomes false as not greater then 5 
so else part code block will be executed
int number = 3;
if(number > 5)
{
 cout<<"Greater then 5";
}
else
{
 cout<<"Less then 5";
}

C++ Program to use if-else statement

if else statement
If else statement
Output

if else statement output
If else statement output

Post a Comment

Previous Post Next Post

In Article Ads 1 Before Post

In Article Ads 2 After Post