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

The program given below gives a compiler error in two lines.

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

The program given below gives a compiler error in two lines.

#include <stdio.h>

#define pull 45          //line2
#define pulll 46         //line 3

int main()
{
    int zx;
    zx = pulll;          //line 7
    pulll = pull;        //line 8
    pull = zx;           //line 9
    printf("%d\n%d", pull, pulll);  //line 10
    return 0;
}

Find the erroneous line numbers.

Choose one option.
Show answer & explanation
Answer: A. Line 8 and Line 9

#define creates compile-time substitutions, not variables. Lines 8 and 9 attempt to assign values to pull and pulll as if they were variables, but they are macros and cannot be reassigned. The compiler will reject these lines with "lvalue required" or similar errors because macros are not lvalues.

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

  1. Line 2: #define pull 45 – creates a macro; valid.
  2. Line 3: #define pulll 46 – creates a macro; valid.
  3. Line 7: zx = pulll; – reads the macro value (becomes zx = 46;); valid.
  4. Line 8: pulll = pull; – attempts to assign to macro pulll (becomes 46 = 45;); COMPILER ERROR (lvalue required).
  5. Line 9: pull = zx; – attempts to assign to macro pull (becomes 45 = zx;); COMPILER ERROR (lvalue required).
  6. Line 10: printf(...) – reads macro values; valid.

Macros are textual substitutions and cannot be used on the left-hand side (lvalue) of an assignment. The two erroneous lines are Line 8 and Line 9.