The “if” Control Structure, Example 1
•
#include <iostream>
•
int main()
•
{
•
int x = 6, y = 12;
•
if ( x > 5 )
•
{
•
cout << “y = “ << y << endl;
•
}
•
cout << “x = “ << x << endl;
•
return 0;
•
}
What does this program print?
Since x > 5 is true the cout statement between the if statements braces is executed and y = 12 is printed.
Then the statements after the if statement are executed so the program then prints x = 6.