OA. free
Free
Qualcomm Embedded Systems & Hardware Embedded Systems & Hardware Medium

Image 1 - Code Analysis Question: Given the following C code snippet (lines 23-31): What is...

Qualcomm technical mcq question, verified with a worked answer. Free to practise - no sign-up.

Image 1 - Code Analysis Question:**

Given the following C code snippet (lines 23-31):

}

printf("%d", count);
return 0;
}

int number(int n)
{
    if (n <= 1)
        return 1;
    else if (n > 1)
    {
        return number(n - 1) | (n + 1);
    }
    return number(n - 1) & (n - 1);
}

What is the output when this function is called?

Choose one option.
Show answer & explanation
Answer: C. C) 5

Hex addition: E + 1 = F (15). 4 + D = 4 + 13 = 17 = 16*1 + 1 (sum 1, carry 1). 3 + 7 + 1 = B (11). Result is (B1F)₁₆.

Step-by-step Derivation:
Step 1: E_16 (14) + 1_16 = 15 = F_16.
Step 2: 4_16 + D_16 (13) = 17 = 1*16 + 1 => 1 with carry 1.
Step 3: 3_16 + 7_16 + 1_16 = 11 = B_16.
Step 4: Sum = (B1F)₁₆.