C Quiz – 110 | Question 1

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.