Re: [algogeeks] Please explain the output
#includestdio.h #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 vaibhav200...@gmail.comwrote: #includestdio.h #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
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 sachindr...@gmail.comwrote: #includestdio.h #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 vaibhav200...@gmail.comwrote: #includestdio.h #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
hmm i got it.thnx On Thu, Jun 23, 2011 at 4:05 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: 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 sachindr...@gmail.comwrote: #includestdio.h #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 vaibhav200...@gmail.comwrote: #includestdio.h #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
#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 vaibhav200...@gmail.comwrote: #includestdio.h #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
COOL BRO THIS IS A GOOD SOLN On Tue, Apr 5, 2011 at 4:10 PM, Azhar Hussain azhar...@gmail.com 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 vandana@gmail.comwrote: 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: #includestdio.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. -- 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
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
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 akk5...@gmail.com wrote: #includestdio.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. -- 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
thx pratik On Sat, Apr 9, 2011 at 8:13 PM, Pratik Kathalkar dancewithpra...@gmail.comwrote: 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 akk5...@gmail.com wrote: #includestdio.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. -- 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
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: #includestdio.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.
Re: [algogeeks] please explain the output
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.comwrote: 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: #includestdio.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.
Re: [algogeeks] please explain the output
*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 kumar.anuj...@gmail.com wrote: #includestdio.h 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.comalgogeeks%2bunsubscr...@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.