Monday, 6 April 2015

C if statement

Syntax :
if(expression)
   statement1;
Explanation :
  • Expression is Boolean Expression
  • It may have true or false value

Meaning of If Statement :
  • It Checks whether the given Expression is Boolean or not !!
  • If Expression is True Then it executes the statement otherwise jumps to next_instruction
Sample Program Code :
void main()
{
int a=5,b=6,c;
  c = a + b ;

  if (c==11)
       printf("Execute me 1");

  printf("Execute me 2");
}
Output :
Execute me 1

If Statement :

if(conditional)
{
    Statement No 1
    Statement No 2
    Statement No 3
    . 
    .
    .
    Statement No N
}

Note :

    1. More than One Conditions can be Written inside If statement.
    2. Opening and Closing Braces are required only when “Code” after if statement occupies multiple lines.
if(conditional)
    Statement No 1
Statement No 2
Statement No 3
In the above example only Statement 1 is a part of if Statement.
    1. Code will be executed if condition statement is True.
    2. Non-Zero Number Inside if  means “TRUE Condition”
if(100)
    printf("True Condition");

Program flow of If Statement :

No comments:

Post a Comment