The Basic if Statement - C Statement

C examples for Statement:if

Introduction

The general form or syntax of the if statement is:

if(expression)
  Statement1;
Next_statement;

There is no semicolon at the end of the first line.

The second line could be written directly following the first, like this:

if(expression) Statement1;

The expression in parentheses can be any expression that results in a value of true or false.

If the expression is true, Statement1 is executed, after which the program continues with Next_statement.

If the expression is false, Statement1 is skipped and execution continues immediately with Next_statement.

Demo Code

#include <stdio.h>

int main(void)
{
  int number = 0;
  printf("\nEnter an integer between 1 and 10: ");
  scanf("%d",&number);

  if(number > 5)
    printf("You entered %d which is greater than 5\n", number);

  if(number < 6)
    printf("You entered %d which is less than 6\n", number);
  return 0;/*ww  w .  ja v a 2  s  . c  om*/
}

Result


Related Tutorials