---
title: "Syntax of if...else"
subject: "Computer Programming"
chapter: 5
key: "semester_1/computer_programming:syntax-if-else"
source: https://www.bctengineer.com/q/semester_1/computer_programming/syntax-if-else
site: BCT Engineering
---

# Syntax of if...else

Computer Programming · Chapter 5: Control statements

- Asked in: 2067 Asar, 2 marks
- Video: [If else in C Programming | Syntax, Examples, Full Concept | Control statement](https://www.youtube.com/watch?v=TrbPPCy0KXw) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/syntax-if-else
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-5

## Question

Write the syntax used in C programming language for if...else.

## Short answer

if (condition) { statements; } else { statements; } executes the first block when condition is true, otherwise the second block. Exactly one branch runs.

## Answer

**Syntax:**
```text
if (condition)
{
    statements executed when the condition is true;
}
else
{
    statements executed when the condition is false;
}
```
Exactly one of the two blocks executes. A chain is written as `if ... else if ... else`.

**Example:**
```c
#include <stdio.h>
int main(void)
{
    int n = 7;
    if (n % 2 == 0)
        printf("Even\n");
    else
        printf("Odd\n");
    return 0;
}
```
Output:
```text
Odd
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How many blocks execute?
   A. Exactly one
   B. Both
   C. None
   D. Depends on count
   Answer: A. Either/or. (Key point: Blocks)

2. Chain is written as?
   A. if ... elseif
   B. if ... else if ... else
   C. switch if
   D. if else else
   Answer: B. Standard. (Key point: Chain)

3. n=7 prints?
   A. Even
   B. 7
   C. Odd
   D. Nothing
   Answer: C. 7%2 = 1. (Key point: Example)

## Related in Computer Programming

- [Compare switch and if-else-if ladder](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aswitch-vs-ifelse-ladder) — Computer Programming, chapter 5, asked 2×
- [Conditional operator vs if-else; digit sum](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aconditional-operator-vs-ifelse) — Computer Programming, chapter 5
- [Define programming language](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adefine-programming-language) — Computer Programming, chapter 1, asked 3×
- [Syntax of while loop](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asyntax-while) — Computer Programming, chapter 5
- [Syntax of static](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asyntax-static) — Computer Programming, chapter 6
- [Syntax of struct](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asyntax-struct) — Computer Programming, chapter 8

## Related in other subjects

- [8086 assembly language operators](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3A8086-operators) — Microprocessor, chapter 3, asked 3×
- [Syntax of operator overloading](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aoperator-overloading-syntax) — Object Oriented Programming, chapter 5, asked 4×
- [Class and function template with syntax](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aclass-function-template-syntax) — Object Oriented Programming, chapter 9, asked 4×
- [Default arguments and their syntax](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Adefault-arg-define-syntax) — Object Oriented Programming, chapter 3, asked 2×
