DragonFly BSD
DragonFly users List (threaded) for 2005-04
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: code understanding help


From: "Erik Wikström" <erik-wikstrom@xxxxxxxxx>
Date: Sun, 3 Apr 2005 19:09:00 +0200

"Terry Tree" <terry.tree@xxxxxxxxx> wrote in message
news:60e7ec9505040309364929a941@xxxxxxxxxxxxxxxxx
> I'm trying to go through a book on programming in C and I'm having
> problem understanding the second example in the book.
>
> $cat 2.c
>
> #define PRINTX printf("%d\n", x);
>
> int
> main(int argc, char *argv[])
> {
>     int x = 2, y, z;
>
>     x *= 3 + 2; PRINTX;
>     x *= y = z = 4; PRINTX; // the output makes no sense
>     x = y == z; PRINTX;
>     x == (y = z); PRINTX;
> }
>
> Looking at line x *= y = z = 4; from my point of view the output
> should be 8 but it is 40.

Allow me to post another question, I have no experience with C but the third
line looks fishy to me. Would in not be interpreted as x =(y==z), which
should be true, but x is an int. I know of inexplicit casting from int to
bool but never heard of bool to int. Am I missing something?

--
Erik Wikström





[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]