c code

0 views
Skip to first unread message

shwetha....@gmail.com

unread,
Oct 26, 2006, 5:05:32 AM10/26/06
to PESCETechVidhyarthi
hi this is shwetha...i hav a c code...but i am getting a different ans
when i run it in windows and linux environment...can i get why this is
so...

the c code is


main()
{
int x=7;
printf("%d\n", x= x++ * x++);
printf("%d\n",x);
}

bharadwa...@rediffmail.com

unread,
Oct 26, 2006, 7:27:47 AM10/26/06
to PESCETechVidhyarthi
Hello Shwetha...
That is an interesting thing... Try running this code using
turbo c compiler and visual studio vc++ compiler, they themselves will
give different results...
TC gives u 56 56 , where as VC++ gives u 49 51 !!!!

(Let me warn u that even I didnt know about this strange behaviour
untill recently... One of the messages on "Bdotnetstudent" had a
similar doubt and when this doubt was cleared by another member I came
to know about it...)

There is something known as "sequence point" which is the point at
which the side effects (such as post increment due ++) of any
expression will be complete or null. Since the statement x = x++ * x++
does not define any such proper sequence point, it is left to the
implementation of the compiler to decide how to tackle these kinds of
problems...
Well for more information on sequence point go to this address by
pasting it in ur explorer bar: http://c-faq.com/expr/seqpoints.html

Reply all
Reply to author
Forward
0 new messages