Re: unexpected result
- From: jaysome <jaysome@xxxxxxxxxxx>
- Date: Thu, 09 Mar 2006 22:20:17 -0800
Jack Klein wrote:
On 8 Mar 2006 01:17:27 -0800, "Ankur" <ankur.mcp@xxxxxxxxx> wrote in
comp.lang.c:
#1, DON'T TOP POST IN THIS GROUP. I have put your reply where it
belongs, after the original post.
ashu wrote:
hi
look at this code
include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}
acc. to me the values of i & j are 27,5 respectively & rightly so as i
ran this on turbo c++ compiler but if i ran this on lcc-win32 compiler
i got 32 & 5 for i & j respectively.
why this is so
hi anshu
it all compiler depenedent
in lcc-win32 compiler
first the code run on right to left
means i=4*4*2
it give 32 for i
but in turboc compiler it execute code left to right and take big value
among it i.e. 3
so thats y its give 27.
No, it is not "all compiler dependent", it is undefined behavior.
There is no right result, there is no wrong result, as far as the C
language is concerned there is no need for a result at all.
There's always a result. But the result may not be as expected. Hence unexpected behavior.
--
jay
.
- Follow-Ups:
- Re: unexpected result
- From: Keith Thompson
- Re: unexpected result
- From: Vladimir S. Oka
- Re: unexpected result
- References:
- unexpected result
- From: ashu
- Re: unexpected result
- From: Ankur
- Re: unexpected result
- From: Jack Klein
- unexpected result
- Prev by Date: Re: Learning C
- Next by Date: Re: p[assing by reference
- Previous by thread: Re: unexpected result
- Next by thread: Re: unexpected result
- Index(es):
Relevant Pages
|