Multiple choice technology programming languages

what is the output of the programme? #define ABC 20 #define XYZ 10 #define XXX ABC - XYZ void main() { int a; a = XXX * 10; printf("%d ", a); }

  1. 20

  2. 10

  3. 100

  4. -80

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The macro XXX expands to 'ABC - XYZ', which becomes '20 - 10'. The expression 'a = XXX * 10' becomes 'a = 20 - 10 * 10'. Due to operator precedence, multiplication happens before subtraction: 10 * 10 = 100, then 20 - 100 = -80.

AI explanation

To determine the output of the given program, let's go through each line of code:

  1. #define ABC 20 - This line defines a macro ABC with the value 20.
  2. #define XYZ 10 - This line defines a macro XYZ with the value 10.
  3. #define XXX ABC - XYZ - This line defines a macro XXX which is equal to the value of ABC minus XYZ. Substituting the values, XXX becomes 20 - 10, which is 10.
  4. void main() - This line declares the main function.
  5. int a - This line declares an integer variable 'a'.
  6. a = XXX * 10 - This line assigns the value of XXX multiplied by 10 to the variable 'a'. Substituting the value of XXX, the expression becomes a = 10 * 10, which is 100.
  7. printf("%d ", a); - This line prints the value of 'a' using the printf function.

Therefore, the output of the program will be "100".

The correct answer is C) 100.