Few Important things about macros, before I explain the output 1. Macros are replaced in passes. 2. Macros are not recursive.
regarding the output remember the rule for expansion "A parameter in the replacement list, *UNLESS* preceded by a # or ## preprocessing token or followed by a ## preprocessing token, is replaced by the corresponding argument after all macros contained therein have been expanded". In other words, macros are replaced "inside out" unless # or ## exists printf("%s",g(f(1,2))); is replaced as #f(1,2) ---> "f(1,2)" according to the replacement rule. printf("\t%s",h(f(1,2))); As this does not replace with # or ## directly, "inside out" expansion leads to h("1,2") --> g('1,2") --> "1,2" for the first pass printf("%s", "f(1,2)"); ---> g(a) #a printf("\t%s", h("1,2")); second pass printf("%s", "f(1,2)"); ---->> not processed(exhausted) printf("\t%s", g("1,2")); --> h(a) g(a) Third pass printf("%s", "f(1,2)"); ---->> not processed(exhausted) printf("\t%s", "1,2"); --> g(a) #a Hope this answers your question. - Azhar. On Tue, Apr 5, 2011 at 3:22 PM, Vandana Bachani <vandana....@gmail.com>wrote: > Hi Arvind, > These are preprocessor specific operators. Check out > http://msdn.microsoft.com/en-us/library/wy090hkc(v=vs.80).aspx > > -Vandana > > On Tue, Apr 5, 2011 at 12:45 PM, Arvind <akk5...@gmail.com> wrote: > >> #include<stdio.h> >> >> #define f(a,b) a##b >> #define g(a) #a >> #define h(a) g(a) >> >> int main() >> { >> printf("%s",g(f(1,2))); >> printf("\t%s",h(f(1,2))); >> return 0; >> } >> >> >> >> i have run this program in gcc compiler and getting : f(1,2) 12 as >> output. >> can anyone explain the reason for getting this output? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.