If statement in C programming language with syntax

If statement in C

The decision statements is a way to decide on different alternative

if statement

Syntax
if (test condition)
{
statements;
}
statement y;

Note : no semi-colon after the test condition

Condition is true

Rendered by QuickLaTeX.com

#include <stdlib.h>
int main()
{
    int a=5;   // initialize a to 5
    if(a>2)   //test if a greater than 2
    {
        a++;   //  a increment
    }
        printf("A=%d",a); // print  a
    return 0;
}

Output

A =6

Condition is False

Rendered by QuickLaTeX.com

#include <stdlib.h>
int main()
{
    int a=5;
    if(a>8)
    {
        a++;
    }
        printf("A=%d",a);
    return 0;
}

Output

A=5

Mohammed Anees

Hey there, welcome to aneescraftsmanship I am Mohammed Anees an independent developer/blogger. I like to share and discuss the craft with others plus the things which I have learned because I believe that through discussion and sharing a new world opens up

Leave a Reply

Your email address will not be published.