Aspire Faculty ID #13651 · Topic: JAMIA MILLIA ISLAMIA MCA 2023 · Just now
JAMIA MILLIA ISLAMIA MCA 2023

 What is the output of the following C program?

int main()
{
    char ch = 'A';
    int x = 97;
    int y = sizeof(++x);
    printf("\nx is %d", x);
    while (ch <= 'F')
    {
        switch (ch)
        {
            case 'A':
            case 'B':
            case 'C':
            case 'D': ch++; break;
            case 'E':
            case 'F': ch++;
        }
        putchar(ch);
    }
    return 0;
}

Solution

Solution:

1️⃣ `int y = sizeof(++x);`  
→ `sizeof` is a compile-time operator, so `++x` is **not evaluated**.  
Hence, `x` remains unchanged (`x = 97`).

2️⃣ `printf("\nx is %d", x);`  
→ prints: `x is 97`

3️⃣ Loop execution:

| ch  | switch(ch) executes | putchar(ch) prints | next value of ch |
|------|----------------------|--------------------|------------------|
| 'A'  | falls to case 'D' → ch++ → break | prints `'B'` | 'B' |
| 'B'  | falls to case 'D' → ch++ → break | prints `'C'` | 'C' |
| 'C'  | falls to case 'D' → ch++ → break | prints `'D'` | 'D' |
| 'D'  | case 'D' → ch++ → break | prints `'E'` | 'E' |
| 'E'  | case 'E' → fall through to case 'F' → ch++ | prints `'F'` | 'F' |
| 'F'  | case 'F' → ch++ | prints `'G'` | 'G' (loop ends) |

Output sequence = `x is 97 BCDEFG`



Previous 10 Questions — JAMIA MILLIA ISLAMIA MCA 2023

Nearest first

Next 10 Questions — JAMIA MILLIA ISLAMIA MCA 2023

Ascending by ID
Ask Your Question or Put Your Review.

loading...