If statement checks whether the test expression satisfies the condition or not. If it satisfies it enters into block of if statements bounded by curly braces.
if (test expression is true)
Program working steps
- First line of the program is the comment, 2nd & 3rd lines are preprocessor statments which include definition of functions like printf, scanf, clrscr etc.
- From void main() function the program execution starts.
- Declaration of variable stack with integer data type.
- clrscr() function clears the console window.
- 9th line prints the characters quoted in double quote and 10th line asks for user input and stores the value entered into the variable stack.
- If condition expression is true then the next statment on line no.12 will be executed printing 'Stack is overflow'. And if expression is false then 12th line statement will be ignored.
- So user should enter value greater than ten to execute the if block statement.
- In the above example we have used single statement condition body, you can use multiple statement condition body using opening and closing curly brackets.
- getch() function takes the single input character from the keyboard and that character is not display on the console screen.
You can use multiple condition expression in if condition statement like:
if (i>1 && j<2)