From: Ineiev <ineiev@gmail.com>
To: "W.H. Kalpa Pathum" <callkalpa@gmail.com>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Could you please explain this code segment
Date: Thu, 17 Dec 2009 08:46:00 -0000 [thread overview]
Message-ID: <7511306b0912170022m169d3eecqcd80bc39ab74f21a@mail.gmail.com> (raw)
In-Reply-To: <79fa0d5a0912162253p49d17f36s2e65d4be8394df69@mail.gmail.com>
On 12/17/09, W.H. Kalpa Pathum <callkalpa@gmail.com> wrote:
> Could you please explain how the output differs (when assigned to the
> variable b and in printf statement) and the way the compiler executes
> each segment of the variable?
>
> int main(){
> int a = 10;
> int b = (++a) + (++a);
> printf("%d %d %d %d\n", b, a++, a, ++a);
> printf("%d %d %d %d\n", ++a + ++a, a++, a, ++a);
The program evaluates the arguments first and calls
printf then.
You can't do such things if you want to rely on the result, because
the order of the arguments evaluation is implementation-specific (to
begin with).
next prev parent reply other threads:[~2009-12-17 8:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-17 8:22 W.H. Kalpa Pathum
2009-12-17 8:46 ` Ineiev [this message]
2009-12-17 12:20 ` John (Eljay) Love-Jensen
2009-12-17 17:04 ` Bob Plantz
2009-12-17 18:52 ` Joel Dice
2009-12-17 19:53 ` Bob Plantz
2009-12-17 20:11 Bill McEnaney
2009-12-17 20:22 ` Brian Budge
2009-12-17 20:28 ` Joel Dice
2009-12-17 22:02 Bill McEnaney
2009-12-18 5:11 ` Joel Dice
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7511306b0912170022m169d3eecqcd80bc39ab74f21a@mail.gmail.com \
--to=ineiev@gmail.com \
--cc=callkalpa@gmail.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).