C - If...else Control Statements

<<Previous

Next >>





The if statement can response only the true condition. In case of if...else statement, it can response in both conditions such as true and false.

Syntax

	if(conditional-expression)
                  /* statements can be executed only the conditional_expression is true */
          statement1;
	else
                  /* statements can be executed only the conditional_expression is false*/
         statement2;
You can also execute
	if (conditional_expression){
                /* statements can be executed only the conditional_expression is true */
          compound statements;
	}else {
           /* statements can be executed only the conditional_expression is false */
        compound statements;
	}

The if..else statement checks whether the condition is true or false. If the condition is true, then the if block will be executed . If the condition is false, then the else block will be executed.

Flow Chart


Example C Program for if..else statement

#include <stdio.h>
#include <conio.h>

int main()
{
	int A=25;
	int B=40;
	if (A > B){
		printf("The A value is greater than B \n");
		A = A - 5;
	}
	else {
		printf("The A value is not greater than B \n");
		A = A + 5;
	}
	printf("The A value is: %d \n The B value is :%d",A,B);
	return(0)
}

Output

The A value is not greater than B
The A value is:30
The B value is:40

<< Previous

Next >>







C - If...else Control Statements

<<Previous

Next >>





The if statement can response only the true condition. In case of if...else statement, it can response in both conditions such as true and false.

Syntax

	if(conditional-expression)
                  /* statements can be executed only the conditional_expression is true */
          statement1;
	else
                  /* statements can be executed only the conditional_expression is false*/
         statement2;
You can also execute
	if (conditional_expression){
                /* statements can be executed only the conditional_expression is true */
          compound statements;
	}else {
           /* statements can be executed only the conditional_expression is false */
        compound statements;
	}

The if..else statement checks whether the condition is true or false. If the condition is true, then the if block will be executed . If the condition is false, then the else block will be executed.

Flow Chart


Example C Program for if..else statement

#include <stdio.h>
#include <conio.h>

int main()
{
	int A=25;
	int B=40;
	if (A > B){
		printf("The A value is greater than B \n");
		A = A - 5;
	}
	else {
		printf("The A value is not greater than B \n");
		A = A + 5;
	}
	printf("The A value is: %d \n The B value is :%d",A,B);
	return(0)
}

Output

The A value is not greater than B
The A value is:30
The B value is:40

<< Previous

Next >>







Learn about Hashing and Hash table

Learn Expression Tree

OS Kernel Architecture

OS Arcitecture of Windows, Linux and MacOS

Learn OS scheduling Algorithms