Re: [algogeeks] problem with increment operator

2012-05-30 Thread Prateek Jain
yups...it is compiler dependent...but a logic is necessary to get it... -- 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

Re: [algogeeks] problem with increment operator

2012-05-30 Thread vIGNESH v
Hai i tried the same in TC compiler. i got the output as 17. I guess the output should be 17 as explained by Prateek Jain On 30 May 2012 02:26, rahul ranjan rahul.ranjan...@gmail.com wrote: it first calculates from right to left and then performs addition so after a++ its still 4(with

Re: [algogeeks] problem with increment operator

2012-05-30 Thread Prateek Jain
okk -- 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

Re: [algogeeks] problem with increment operator

2012-05-30 Thread Navin Kumar
Hey answer will be 18 as follows. First ++a(5)+ ++a(6) + a++(6)=17 + one post increment= 18. On Thu, May 31, 2012 at 3:13 AM, Prateek Jain prateek10011...@gmail.comwrote: okk -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

[algogeeks] problem with increment operator

2012-05-29 Thread ashish pant
#includestdio.h int main() { int a=4; printf(%d\n,++a + ++a + a++); return 0; } according to me output should be 17, but it is coming out to be 18. plz explain it?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group.

Re: [algogeeks] problem with increment operator

2012-05-29 Thread MeHdi KaZemI
At first the value of a is calculated for the statement, that is 6, and then statement is evaluated with a=6 so it is 6 + 6 + 6 = 18 and as you know after that the value of a becomes 7 for the rest of the program. On Mon, May 28, 2012 at 10:02 AM, ashish pant asheesh...@gmail.com wrote:

Re: [algogeeks] problem with increment operator

2012-05-29 Thread Prateek Jain
how is it 6? ++a(5) + ++a(6) + a++(6) it shud be 17 -- 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

Re: [algogeeks] problem with increment operator

2012-05-29 Thread Hassan Monfared
I implemented ++ for a simple class and got 17. class A { public : int val; A(int v):val(v){} int operator++() { cout empty arg called\n; return ++val; } int operator++(int x) { cout x:arged arg called\n; return val++; } }; -- A b(4); cout ++a + ++a +a++endl; 17 but

Re: [algogeeks] problem with increment operator

2012-05-29 Thread rahul ranjan
it first calculates from right to left and then performs addition so after a++ its still 4(with a promise to increment in next statement). then ++a makes it 5. then further ++a makes it 6 now the addition phase comes into play value of a is 6 now so total 18 if it

Re: [algogeeks] problem with increment operator

2012-05-29 Thread atul anand
@all : no need to argue on this ...output is compiler dependent ... it violates sequence point rule :) :). On Wed, May 30, 2012 at 2:26 AM, rahul ranjan rahul.ranjan...@gmail.comwrote: it first calculates from right to left and then performs addition so after a++ its still 4(with a