What are the if-else Statement in C Language ??? with Free Notes

What are the if-else Statement ???

if-else Statement is the Conditional Control Structure Statement which is used for checking conditions. In this the condition works in true or false situation. Like if the Condition is true the block of code will be executed and if the condition is false then another or 2nd block of code will be executed. Let’s understand this scenario with Syntax,

Syntax: –

Here is the Syntax of the if-else Statement,

if (condition) {
    // code block to execute if condition is true
} else {
    // code block to execute if condition is false
}

Here, “condition” is an expression that evaluates to either true or false. Now Let’s understand this with example in briefly.

Example: if-else

Here is the example of the else-if condition,

#include <stdio.h>

int main() {
    int num = 10;

    // If-else statement example
    if (num % 2 == 0) {
        printf("%d is even.\n", num);
    } else {
        printf("%d is odd.\n", num);
    }

    return 0;
}

Explanation about Example:

Here we use if-else Statement, which is used to check the “num” variables is the even or odd. In this example, if the condition is true then it will show the “num” is even but if the condition is false then it will show the “num” is odd.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top