OA. free
Free
Qualcomm Embedded Systems & Hardware Core Computer Science Medium

Which of the following lines will cause a compilation error in C?

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

Which of the following lines will cause a compilation error in C?

struct book
{
    int b1;
    unsigned float b2;     // Line 1
} b;

union notebook
{
    static int n1;         // Line 2
    short int n2;          // Line 3
} n;

printf("%d", sizeof(b) + sizeof(n));    // Line 4
Choose one option.
Show answer & explanation
Answer: A. Line 1 and Line 2 (unsigned float is invalid; static member in union is invalid)

Line 1 is invalid because unsigned float is not a valid type qualifier combination in C—only unsigned can modify integer types, not floating-point types. Line 2 is invalid because static storage class cannot be used for union members; only instance members are allowed. Line 3 is valid (unions can have short int members), and Line 4 is valid (sizeof returns a size_t, which can be printed with %zu or cast to int).

Step-by-step Derivation:
Analyze each line for C language constraints: (1) Type qualifiers: unsigned applies only to integer types (int, char, short, long), never to float or double. Using unsigned float violates this rule and causes compilation error. (2) Union member restrictions: Union members cannot have storage class specifiers like static, extern, or register. The static int n1; declaration violates this rule and causes compilation error. (3) Line 3 is syntactically and semantically valid—unions can contain short int members without issue. (4) Line 4 is valid—sizeof() returns a value that can be used in expressions and printed; while %d expects int and sizeof() returns size_t, most compilers will accept this with implicit conversion or a warning, not a hard error. Therefore, Lines 1 and 2 cause compilation errors.