Ok well i checked for your output but unlike you 
i found the same answer in both the cases and that was that 
it must be i.e. 12;
In the assigning statement of v
you are telling the compiler like this


(m++)+(++m)
it means first take m and after the execution increase its value by 1 and add m 
again but before the execution increase its value by 1
so before the execution of the above statement the value of m 
is set to 6(by an increment of 1)
and yeah the result will be generated as m+m
i.e.6+6 =12
after the execution of statement the m
will be set to 7
So the answer is 12.
please have a look once again on your program.
I hope you will get it.
best of luck!!


________________________________
From: Aliya Awais <[email protected]>
To: [email protected]
Sent: Wednesday, May 27, 2009 2:37:25 PM
Subject: [c-prog] confusing output





hi ! can someone please tell me the difference between output of given two 
expression in C++ programs , how expressions are evaluated  in these two cases?

#include<iostream. h> 
void main() 
{  
int m=5,v=0,u=0; 
v=v+(m++)+(+ +m);  
cout<<v<<endl;    //output is 11 
} 

#include<iostream. h> 
void main() 
{  
int m=5,v=0,u=0; 
v=(m++)+(++m) ; 
cout<<v<<endl;    //output is 12 (why confusing) 
} 

what is difference between v=v+(m++)+(+ +m);  and v=(m++)+(++m) ;  .
 
thanks

[Non-text portions of this message have been removed]


   


      

[Non-text portions of this message have been removed]

Reply via email to