Re: printf output
- From: Jack Klein <jackklein@xxxxxxxxxxx>
- Date: Mon, 16 Feb 2009 21:50:45 -0600
On Mon, 16 Feb 2009 19:32:37 -0800 (PST), Keep Asking
<ask8y@xxxxxxxxx> wrote in comp.lang.c:
What is output of following printf should be?
There is nothing that it "should be".
i=0;
printf("i=%d i++=%d i++=%d", i, i++, i++)?
I was surprised when I was the print out.
You have no business being surprised, because you had no right to
expect anything. You have broken the rules and generated undefined
behavior.
Once you do that, the C language does not specify or care what
happens. Anything is as right or wrong as anything else.
You have modified the (type unknown, but assume int) object 'i' more
than once, and also modified it and read its value separately, both
without a sequence point in between.
Search this group on Google groups for the phrase "sequence point" to
see many, many discussions.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
.
- Follow-Ups:
- Re: printf output
- From: nick_keighley_nospam
- Re: printf output
- From: Richard
- Re: printf output
- References:
- printf output
- From: Keep Asking
- printf output
- Prev by Date: printf output
- Next by Date: Re: printf output
- Previous by thread: printf output
- Next by thread: Re: printf output
- Index(es):
Relevant Pages
|
Loading