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

Consider the following code segment:

if (n > 0)
    for (i = 0; i < 3; i++)
        if (array[i] > 0)
            printf("%d\n", array[i]);
        else
            printf("\n n is negative\n");

Here, ‘else’ is paired with which ‘if’?

Solution

Solution: In C, **“else” is always paired with the nearest unmatched “if”** (no braces rule). Here: - The inner `if (array[i] > 0)` is the **nearest unmatched `if`** before `else`. So, the `else` is paired with the **second (inner)** `if`.

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...