Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 31 Jan 1999 02:36:23 -0500
From:      Malartre <malartre@aei.ca>
To:        hackers@FreeBSD.ORG
Subject:   some weird C
Message-ID:  <36B407F7.1617E743@aei.ca>

next in thread | raw e-mail | index | archive | help
This is not really.. for hackers@freebsd.org, but I cannot find the
answer anywhere.
main()
{
        int     x=4;
        printf("The value of x is %d\n",x);
        printf("The value of \"x += x++\" is %d\n",x += x++);
        x=4;
        printf("The value of x is %d\n",x);
        printf("The value of \"x += ++x\" is %d\n",x += ++x);
}

The results are:

The value of x is 4
The value of "x += x++" is 8
The value of x is 4
The value of "x += ++x" is 10

I was expecting 9, not 10.
since 4+5=9?
Why 10?
I also noticed that cc is reading from right to left. Cool.
Thank You
-- 
[Malartre][malartre@aei.ca][http://www.aei.ca/~malartre/]
[French piss me off - Cartman, South Park][http://9.nws.net/]

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?36B407F7.1617E743>