Re: [algogeeks] Please explain the output

2011-06-23 Thread rajeev bharshetty
#a is the replacement sequence which is substituted in the printf statement
The statements
#define power(a) #a
printf("%d",power(a));

is substituted as

printf("%d","a");

it is replaced with the string literal "a" . then *power(a) is converted as
value at that string literal address.

Hope this solves the problem :)
--
Rajeev N B

I Blog @ www.opensourcemania.co.cc

On Thu, Jun 23, 2011 at 3:40 PM, vaibhav shukla wrote:

> #include
> #define power(a) #a
> int main()
> {
>  printf("%d",*power(432));
>   return 0;
> }
>
>
> ans is 52 on gcc. Explain plss
>
> --
>   best wishes!!
> Vaibhav Shukla
> DU-MCA
>
>  --
> 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.



Re: [algogeeks] Please explain the output

2011-06-23 Thread vaibhav shukla
hmm i got it.thnx

On Thu, Jun 23, 2011 at 4:05 PM, Piyush Sinha wrote:

> printf("%d",*power(432)) will expand as
>
> *printf("%d", *"432")*
>
> "432" represents here a string and *"432" is pointing to the first string
> literal i.e 4 whose ascii value is 52..hence the output is 52
>
>
> On Thu, Jun 23, 2011 at 4:02 PM, Shachindra A C wrote:
>
>>  #include
>> #define power(a) #a
>> int main()
>> {
>>  printf("%d",*power(432));
>>   return 0;
>> }
>>
>> the printf statement, after preprocessing, will look like
>> printf("%d",*"432");
>>
>> so, when u print the value at the first position of the string, 52, which
>> is the ascii value of 4, will be printed.
>>
>> On Thu, Jun 23, 2011 at 3:40 PM, vaibhav shukla 
>> wrote:
>>
>>> #include
>>> #define power(a) #a
>>> int main()
>>> {
>>>  printf("%d",*power(432));
>>>   return 0;
>>> }
>>>
>>>
>>> ans is 52 on gcc. Explain plss
>>>
>>> --
>>>   best wishes!!
>>> Vaibhav Shukla
>>> DU-MCA
>>>
>>> --
>>> 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.
>>>
>>
>>
>>
>> --
>> Regards,
>> Shachindra A C
>>
>> --
>> 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.
>>
>
>
>
> --
> *Piyush Sinha*
> *IIIT, Allahabad*
> *+91-8792136657*
> *+91-7483122727*
> *https://www.facebook.com/profile.php?id=10655377926 *
>
>  --
> 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.
>



-- 
  best wishes!!
Vaibhav Shukla
DU-MCA

-- 
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.



Re: [algogeeks] Please explain the output

2011-06-23 Thread Piyush Sinha
printf("%d",*power(432)) will expand as

*printf("%d", *"432")*

"432" represents here a string and *"432" is pointing to the first string
literal i.e 4 whose ascii value is 52..hence the output is 52


On Thu, Jun 23, 2011 at 4:02 PM, Shachindra A C wrote:

>  #include
> #define power(a) #a
> int main()
> {
>  printf("%d",*power(432));
>   return 0;
> }
>
> the printf statement, after preprocessing, will look like
> printf("%d",*"432");
>
> so, when u print the value at the first position of the string, 52, which
> is the ascii value of 4, will be printed.
>
> On Thu, Jun 23, 2011 at 3:40 PM, vaibhav shukla 
> wrote:
>
>> #include
>> #define power(a) #a
>> int main()
>> {
>>  printf("%d",*power(432));
>>   return 0;
>> }
>>
>>
>> ans is 52 on gcc. Explain plss
>>
>> --
>>   best wishes!!
>> Vaibhav Shukla
>> DU-MCA
>>
>> --
>> 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.
>>
>
>
>
> --
> Regards,
> Shachindra A C
>
> --
> 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.
>



-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

-- 
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.



Re: [algogeeks] Please explain the output

2011-06-23 Thread Shachindra A C
#include
#define power(a) #a
int main()
{
 printf("%d",*power(432));
  return 0;
}

the printf statement, after preprocessing, will look like
printf("%d",*"432");

so, when u print the value at the first position of the string, 52, which is
the ascii value of 4, will be printed.

On Thu, Jun 23, 2011 at 3:40 PM, vaibhav shukla wrote:

> #include
> #define power(a) #a
> int main()
> {
>  printf("%d",*power(432));
>   return 0;
> }
>
>
> ans is 52 on gcc. Explain plss
>
> --
>   best wishes!!
> Vaibhav Shukla
> DU-MCA
>
>  --
> 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.
>



-- 
Regards,
Shachindra A C

-- 
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.



Re: [algogeeks] please explain the output

2011-04-09 Thread ArPiT BhAtNaGaR
thx pratik

On Sat, Apr 9, 2011 at 8:13 PM, Pratik Kathalkar
wrote:

> u can see the pre-processed file using gcc -E prog_name.cand @
> bottom u can see what actually the code is doing.
>
>
> On Tue, Apr 5, 2011 at 12:45 PM, Arvind  wrote:
>
>> #include
>>
>> #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.
>>
>>
>
>
> --
> Pratik Kathalkar
> CoEP
> BTech IT
> 8149198343
>
>
>  --
> 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.
>



-- 
Arpit Bhatnagar
(MNIT JAIPUR)

-- 
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.



Re: [algogeeks] please explain the output

2011-04-09 Thread Pratik Kathalkar
u can see the pre-processed file using gcc -E prog_name.cand @
bottom u can see what actually the code is doing.

On Tue, Apr 5, 2011 at 12:45 PM, Arvind  wrote:

> #include
>
> #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.
>
>


-- 
Pratik Kathalkar
CoEP
BTech IT
8149198343

-- 
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.



Re: [algogeeks] please explain the output

2011-04-09 Thread Prakash D IT @ CEG
nice explanation

-- 
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.



Re: [algogeeks] please explain the output

2011-04-09 Thread ArPiT BhAtNaGaR
COOL BRO THIS IS A GOOD SOLN

On Tue, Apr 5, 2011 at 4:10 PM, Azhar Hussain  wrote:

> 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 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  wrote:
>>
>>> #include
>>>
>>> #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.
>



-- 
Arpit Bhatnagar
(MNIT JAIPUR)

-- 
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.



Re: [algogeeks] please explain the output

2011-04-05 Thread Azhar Hussain
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 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  wrote:
>
>> #include
>>
>> #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.



Re: [algogeeks] please explain the output

2011-04-05 Thread Vandana Bachani
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  wrote:

> #include
>
> #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.



Re: [algogeeks] please explain the output

2010-11-05 Thread Piyush
*The prototype of printf is*
*int printf(const char ***format**, ...);*
*
*
*Thus it takes a string and then variable number of arguments.*
*
*
*Every argument passed after (char *format)string is to resolve the"%"
inside the string (which is passed as the first argument)*
*
*
*Thus "anuj" will be printed as normal as printf("anuj");*
*Since "anuj" which is char *format for the printf function does not need to
resolve % because there aren't any.*
*
*
It will be good to read the printf implementation in  Dennis Ritchie to get
a better understanding

On Fri, Nov 5, 2010 at 7:58 PM, ANUJ KUMAR  wrote:

> #include
> int main()
> {
>printf("anuj","kumar");
>return 0;
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@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 algoge...@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.