if Statement in c

(a) The if statement 

(b) The if-else statement 
(c) The conditional operators 
Here when if ststement condition true then exicute code within if for example:-

if ( this condition is true ) 

{

execute this statement ; 

...................

}

this expressionis true if
 x == yx is equal to y
x != yx is not equal to y
x < yx is less than y
x > yx is greater than y
x <= yx is less than or equal to y
x >= yx is greater than or equal to y

Here a example of if statement given below:-

if ( i

{

printf("Hello");

}

Here if i will be less then j then it print "Hello" else this print nothing imean no output. 

if-else Statement:-

In this case we have 2 option if condition true execute some code and if condition is false then execute other code for example:-

if ( this condition is true ) 

{

execute this statement ; 

...................

}

else

{

execute this statement ; 

...................

}


if ( i < j)

{

printf("i is less then j");

}

else

{

printf("i is not less then j");

}

Here if i will be less then j then it print i is less then j and if i will not be less then j then it print i not less then j.


if ( per >= 60 )

{

printf ( "First division" ) ; 

}

else if ( per >= 50 )

{

printf ( "Second division" ) ;

}

else if ( per >= 40 )

{

printf ( "Third division" ) ;

}

else

{

printf ( "fail" ) ; 

}

Here per is percentage which decide division of student with above example. Here we are checking multiple condition one by one and get the correct result, if any condition true then no need to check next else-if condition.

The Conditional Operator:-

The conditional operators ? and : are sometimes called ternary operators since they take three arguments. In fact, they form a kind of foreshortened if-then-else. Their general form is, 

expression 1 ? expression 2 : expression 3 

y = ( x > 8 ? 2 : 5 ) ; 

This statement will store 2 in y if x is greater than 8, otherwise it will store 5 in y.



You may also like

What is PHP?

PHP stands for PHP: Hypertext pre-processor, with that PHP standi...

What is ASP.NET?

ASP.NET, the next version of ASP, is a programming framework used...

What is Data Structure?

A data structure is a group of data elements grouped together und...

What is C#?

C# removes some of the complexities and pitfalls of languages suc...

What is Math?

Math is no Definition it has only Calculation.Closure Property of...

What is Oracle?

Based in Redwood, California, Oracle Corporation is the largest s...

Function in java

A function in Java language is a block of code that performs a sp...

Do-While Loop in java

The do-while loop looks like this:do{ this ; and this ; and this ...