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

What will be the output of the above C program?

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

struct ghi
{
    int p;
};

struct abc abc;
union def def;
struct ghi ghi;
printf("%d %d %d ", sizeof(abc), sizeof(def), sizeof(ghi));
return 0;

What will be the output of the above C program?

Choose one option.
Show answer & explanation
Answer: D. Compile time error

The program attempts to declare variables of struct abc and union def, but these types are never defined in the code. Only struct ghi is defined. The compiler will generate errors when trying to instantiate undefined types, preventing compilation.

Step-by-step Derivation:
Step-by-step analysis:

  1. struct ghi is defined with one int member p.
  2. struct abc abc; — attempts to declare a variable of type 'struct abc', but struct abc has never been defined. This is a compilation error.
  3. union def def; — attempts to declare a variable of type 'union def', but union def has never been defined. This is also a compilation error.
  4. struct ghi ghi; — this is valid since struct ghi was defined, but the program never reaches this point due to earlier compilation errors.
  5. Result: The program fails to compile with undefined type errors for 'struct abc' and 'union def'.