[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: i = i++
read some C faqs . they say changing a variable in a statement which refers it twice isn't valid . so
anything like
++i = i; or
++i = i++; or
printf("%d %d",++i,i++); are not valid & thus may differ from compiler to compiler
_______
deepak
>hi
>what should the outcome of this program be ?
>
>void main()
>{
> int i = 1 ;
> i = i++ ;
> cout<<i ;
>}
>
>i got the oputput as 2. but the following program gave
>me 1
>
>class A
>{
> int num ;
> public :
> A(int n) : num(n) {}
> A & operator = (const A & rhs)
> {num = rhs.num ; return *this ;}
> A operator ++(int)
> {A temp(num) ; num = num + 1 ; return temp ;}
> operator int()
> {return num ;}
>} ;
>
>void main()
>{
> A a(1) ;
> a = a++ ;
> cout<<a ;
>}
>
>the result is the same on g++ and vc. i dont
>understand. please help.
>sindhoor
>
>__________________________________________________
>Do You Yahoo!?
>Yahoo! Photos - Share your holiday photos online!
>http://photos.yahoo.com/
>
>---------------------------------------------
>Find out more about this and other Linux India
>mailing lists at http://lists.linux-india.org/
>
>