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

Discussion

What will be the output of the program?

#include <stdio.h>
#define JOIN(s1, s2) printf("%s=%s %s=%s \n", #s1, s1, #s2, s2);
int main()
{
    char *str1="India";
    char *str2="BIX";
    JOIN(str1, str2);
    return 0;
}

 

  • A.str1=IndiaBIX str2=BIX
  • B.str1=India str2=BIX
  • C.str1=India str2=IndiaBIX
  • D.Error: in macro substitution

Answer: B

Correct answer: str1=India str2=BIX

Each parameter is used twice: once with #, which stringizes the argument’s text, and once plainly, which yields the pointer. So #s1 becomes "str1" while s1 is the variable holding "India". The output is str1=India str2=BIX - the idiom used by debugging macros that print both a variable’s name and its value.

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

Post your comment

Please log in or register to post a comment.