If Statements (All Types) in C Language – BCA Notes | BCA BKNMU JUNAGADH

If Statements (All Types) in C Language – BCA Notes

Decision-making is an essential part of programming. In C language, we use if statements to execute certain code based on conditions. This post by BCA School explains all types of if statements with examples for BCA students.

If Statements in C

🔹 1. Simple If Statement

Executes a block of code only if the condition is true.

if (marks >= 40) {
    printf("Pass");
}

🔹 2. If-Else Statement

Executes one block if condition is true, another if it is false.

if (marks >= 40) {
    printf("Pass");
} else {
    printf("Fail");
}

🔹 3. Nested If Statement

Used for multiple conditions inside another if statement.

if (marks >= 40) {
    if (marks >= 75) {
        printf("Distinction");
    } else {
        printf("Pass");
    }
} else {
    printf("Fail");
}

🔹 4. If-Else If Ladder

Used to test multiple conditions sequentially.

if (marks >= 75) {
    printf("Distinction");
} else if (marks >= 60) {
    printf("First Class");
} else if (marks >= 40) {
    printf("Pass");
} else {
    printf("Fail");
}

🔹 5. Ternary Operator (Conditional)

Short form of if-else in one line.

(marks >= 40) ? printf("Pass") : printf("Fail");

🎯 Conclusion

All types of **if statements** help control program flow and make decisions based on conditions. BCA students should practice each type to strengthen logical thinking and programming skills.

Post a Comment

Thanks for comment.

Previous Post Next Post