C C++

If Statement in C


Conditional instruction execution is a fundamental necessity for any computer program, and the if statement in C serves as its primary conditional construct.

Syntax

if (condition) {
  // block of code to be executed if the condition is true
}

Example

Run Code
#include 

int main() {
    int number;

    printf("Enter an integer: ");
    scanf("%d", &number);

    if (number > 0) {
        printf("The number is positive.\n");
    }

    printf("This message is always displayed.\n");

    return 0;
}