If Statement Example in C
On this page (6sections)
About this program
This is an example program in simple example programs. Read the concept first: Hello World - Simple C Program, then study the code and output below.
Definition
- The if statement executes based test expression inside the braces.
- If statement expression is to true, If body statements are executed.
- If statement expression is to false, If body statements are skipped.
- IF conditional statement is a feature of this programming language which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false. Apart from the case of branch predication, this is always achieved by selectively altering the control flow based on some condition.
- Simply, Block will execute based on If condition or value.
Syntax
if (expression) // Body will execute if expression is true or non-zero
{
code here
}
Example Program for Simple If:
/* Example Program For If In C Programming Language
little drops @ thiyagaraaj.com
Coded By:THIYAGARAAJ MP */
// Header Files
#include<stdio.h>
#include<conio.h>
//Main Function
int main()
{
// Variable Declaration
int a;
//Get Input Value
printf("Enter the Number :");
scanf("%d",&a);
//If Condition Check
if(a > 10)
{
// Block For Condition Success
printf("%d Is Greater than 10",a);
}
// Wait For Output Screen
getch();
//Main Function return Statement
return 0;
}
Sample Output:
Enter the Number :15
15 Is Greater than 10
Related Pages
Learn the concept first, then study the code:
- C Programs — Browse all C Programs.
- Hello World - Simple C Program — Tutorial — your first C program explained line by line.
- Hello World C Language Example Program — More in simple example programs.
- If else Statement Example Program In C Programming Language — More in simple example programs.