Condition Statement MCQ 1 : Non Zero number inside if


C MCQ : if statement > Non Zero number inside if statement


#include<stdio.h>
void main()
{
int num=10;
if(num)
   printf("If Executed");
else
   printf("Else Executed");
}

Options :

  1. If Executed
  2. Else Executed
  3. Compile Error : If Statement must have Condition.
  4. Run-Time Error

[toggle title="Output"]If Executed[/toggle]

Why & How ?
Non Zero Number is TRUE

  1. Any number except Zero in If is considered as TRUE
  2. Value of Variable “num = 10″ which is Considered as TRUE
  3. So IF block gets executed