Open In App

C Quiz – 110 | Question 1

Like Article
Like
Save
Share
Report

Suppose someone writes increment macro (i.e. which increments the value by one) in following ways:




#define INC1(a) ((a)+1)
  
#define INC2 (a) ((a)+1)
  
#define INC3( a ) (( a ) + 1)
  
#define INC4 ( a ) (( a ) + 1)


Pick the correct statement for the above macros.
(A) Only INC1 is correct.
(B) All (i.e. INC1, INC2, INC3 and INC4) are correct.
(C) Only INC1 and INC3 are correct.
(D) Only INC1 and INC2 are correct.


Answer: (C)

Explanation: In C, for macros with arguments, there can’t be any space between macro name and open parenthesis. That’s why only INC1 and INC3 are correct. Basically, “#define INC2 (a) ((a)+1)” results in “INC2” expansion to “(a) ((a)+1)” which is not the desired expansion.

Quiz of this Question


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads