OA. free
Free
MathWorks Core Computer Science Core Computer Science Medium

13.

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

(C Question) Datatype**

What will be the output of following code snippet:

#include<stdio.h>

int main()
{
    double roti = 3.3;
    int Tandoori_roti = (int)roti + 1;
    printf("%d",Tandoori_roti);
    return 0;
}

Pick ONE option

Choose one option.
Show answer & explanation
Answer: C. 4

The double value 3.3 is explicitly cast to int, which truncates the decimal part to 3. Adding 1 gives 4. The printf format specifier "%d" prints an integer, so the output is 4 (not 4.3 or 4.0). Option C is the correct answer; the provided options A and B are both incorrect because printf with %d never outputs decimal notation.

Step-by-step Derivation:
Step 1: roti = 3.3 (double type)
Step 2: (int)roti = 3 (explicit cast truncates decimal)
Step 3: Tandoori_roti = 3 + 1 = 4 (int type)
Step 4: printf("%d", Tandoori_roti) prints 4 as an integer (no decimal point)