public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "W.H. Kalpa Pathum" <callkalpa@gmail.com>
To: gcc-help <gcc-help@gcc.gnu.org>
Subject: Could you please explain this code segment
Date: Thu, 17 Dec 2009 08:22:00 -0000	[thread overview]
Message-ID: <79fa0d5a0912162253p49d17f36s2e65d4be8394df69@mail.gmail.com> (raw)

The following block of code when compiled with gcc (gcc version 4.4.2
20091027 (Red Hat 4.4.2-7) (GCC) ) resulted in the following output.
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);
return 0;
}

OUTPUT
24 13 14 14
36 15 18 18

--
W.H.Kalpa Pathum
http://kalpapathum.blogspot.com
http://thiraya.wordpress.com

             reply	other threads:[~2009-12-17  6:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-17  8:22 W.H. Kalpa Pathum [this message]
2009-12-17  8:46 ` Ineiev
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=79fa0d5a0912162253p49d17f36s2e65d4be8394df69@mail.gmail.com \
    --to=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).