If statement in C++
How is an If statement, Conditional Branching used in C++?
Explanation
If statement is a conditional branching statement used to execute a set of code when the condition is true. This belongs to control structures.
Syntax:
if(expression)
{ Statements }
Example :
#include <iostream.h> using namespace std; void main() { int a=100; int b=200; if (b>a) { cout << "B is greater than A"; } }
|
Result :
B is greater than A
In the above example the condition in the if statement returns a true value so the text given below is displayed.
This is how, conditional branching of program execution can be performed.