[algogeeks] Re: please explain the output
nice explanation On Apr 9, 1:15 pm, ArPiT BhAtNaGaR arpitbhatnagarm...@gmail.com wrote: 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.
[algogeeks] Re: please explain the output
On Apr 5, 3:40 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.
[algogeeks] Re: please explain the output
Crystal Clear. Nicely explained. Thanks! On Apr 5, 3:40 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.
[algogeeks] Re: please explain the output
try removing a=(a++)+(++a); Answer is 13? how? -- 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.
Re: [algogeeks] Re: please explain the output
@ try run in different compiler u may get different result . its compiler dependent result. refer dennis ritchie. -- 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.
[algogeeks] Re: please explain the output
i compiled .. the answer is 17 !! ... its 5+5+7 ..evaluate from left to right On Nov 6, 8:42 pm, bipul21 bipuljai...@gmail.com wrote: #includestdio.h int main() { int a=5; a=a+(a++)+(++a); printf(%d,a); return 0;} answer is 19 but how?? -- 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.
Re: [algogeeks] Re: please explain the output
answer is 17i got in gcc comp On Sun, Nov 7, 2010 at 7:23 PM, Piyush piyushra...@gmail.com wrote: C standard says that between two sequence points object's stored value can be modified only once ( by evaluation of expression), A sequence point occurs in following conditions: 1. at the end of full expression. ( the case for your answer) 2. at the , || , ?: operators 3. at a function call (after the evaluation of all arguments i.e just before the actual call) Since the value of your variable is getting modified more than once between the two sequence points the result is undefined. On Sun, Nov 7, 2010 at 5:33 PM, siva viknesh sivavikne...@gmail.comwrote: i compiled .. the answer is 17 !! ... its 5+5+7 ..evaluate from left to right On Nov 6, 8:42 pm, bipul21 bipuljai...@gmail.com wrote: #includestdio.h int main() { int a=5; a=a+(a++)+(++a); printf(%d,a); return 0;} answer is 19 but how?? -- 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.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.
[algogeeks] Re: please explain the output
#includestdio.h int main() { int a=5; a=a+(a++)+(++a); printf(%d,a); return 0; } answer is 19 but how?? -- 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.
[algogeeks] Re: please explain the output
@Bipul21: This is nonstandard, so the results are compiler-dependent. It is improper to have more than one assignment to the same variable between synchronization points. Dave On Nov 6, 10:42 am, bipul21 bipuljai...@gmail.com wrote: #includestdio.h int main() { int a=5; a=a+(a++)+(++a); printf(%d,a); return 0;} answer is 19 but how?? -- 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.
Re: [algogeeks] Re: please explain the output
firstly evaluate all prefix forms..++a will become 6..then a++ will remain 6..a=7 because postfix form of a will make it so..hence the result 7+6+6=19.. On Sat, Nov 6, 2010 at 9:39 PM, Dave dave_and_da...@juno.com wrote: @Bipul21: This is nonstandard, so the results are compiler-dependent. It is improper to have more than one assignment to the same variable between synchronization points. Dave On Nov 6, 10:42 am, bipul21 bipuljai...@gmail.com wrote: #includestdio.h int main() { int a=5; a=a+(a++)+(++a); printf(%d,a); return 0;} answer is 19 but how?? -- 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.