If-else statement in c++

If statement
syntax

  
  1. If the condition is true it's body execute otherwise dose not execute.
  2. In the case of if in the place of condition always zero and non zero condition is cheked in which zero means condition is false and non zero means condition is true.

Example


#include<iostream.h>
#include<conio.h>
int main()
{
//Assigning value to the variable
int x=50,y=20;
//checking the condition
if(x>y)
{
cout<<"x is greater than y";
}
}

### Output ### x is greater than y


If-else statement:-

syntax

Example


#include<iostream.h>
int main()
{
//Assigning value to the variable
int x=50,y=20;
//checking the condition
if(x==y)
{
cout<<"x is equal to y";
}
else
{
cout<<"x is not equal to y";
}
}
### Output ###
//In the above program condition is false because the value of x=50 and the value of y=20 and they are not equal so else part will execute.
x is not equal to y


If-else ladder:-

  1. It is a part of conditional statement that execute Only one condition at a time.
  2. If all condition are false then else part is executes.
  3. It execute that condition that become first true from the top.
  4. In the case of if in the place of condition is always zero and non zero value is cheked in which zero mean condition false and non zero mean condition true.
Syntax

Comments

Popular posts from this blog

Function in C++ with example & declaration, initialization function in c++

Operators of c++

Storage class in c++