Hi,

See Question 11.17 of C FAQ .
http://c-faq.com/ansi/stringize.html


 In the first case f(1,2)  happens first and in the second case g(X)
happens first and then f(1,2)

Hence in the first case - h(f(1,2,)) = h(12) = 12
and second case = g(f(1,2)) = f(1,2)

In other words
Case1:
- Expanding macro h:
- a => f(1,2)
- Expanding macro f:
- a##b => 12
=> 12
=> g(12)
- Expanding macro g:
- #a is replaced by a string: #a => "12"
O/P => "12"

Case 2:
- Expanding macro g:
- #a => "f(1,2)"
O/P => "f(1,2)"


Macros are evil.

Regards,
Vrashabh Irde

On Mon, Aug 29, 2011 at 1:06 PM, Sahil Garg <[email protected]> wrote:
> Plz explain the solution..
> Acc to me it should be..
> 12
> 12
>
> On 8/29/11, PRATEEK VERMA <[email protected]> wrote:
>> #define g(a) #a
>> replaces any occurrence of g(a) with string a.
>> #define f(a,b) a##b
>> replaces any occurrence of f(a,b) with concatenation of a and b
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
> --
> Sent from my mobile device
>
> Sahil Garg
> Computer Engg. DCE
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to