Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program?

#include <stdio.h>
#define PRINT(int) printf("int=%d, ", int);

int main()
{
    int x=2, y=3, z=4;   
    PRINT(x);
    PRINT(y);
    PRINT(z);
    return 0;
}

 

  • A.int=2, int=3, int=4
  • B.int=2, int=2, int=2
  • C.int=3, int=3, int=3
  • D.int=4, int=4, int=4

Answer: A

Correct answer: int=2, int=3, int=4

A macro parameter may be named int - the preprocessor has no reserved words, and within the macro body the name simply stands for whatever was passed. Each call substitutes its own argument, so the three calls print 2, 3 and 4. The int= inside the string literal is untouched, since macro replacement never reaches inside a string.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.