code understanding help
Devon H. O'Dell
dodell at offmyserver.com
Sun Apr 3 10:15:40 PDT 2005
On Sun, Apr 03, 2005 at 07:09:00PM +0200, Erik Wikström wrote:
>
> "Terry Tree" <terry.tree at xxxxxxxxx> wrote in message
> news:60e7ec9505040309364929a941 at 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
C has no bool type. False evaluates to 0 and true evaluates to 1
is is shown from this code. I really don't like this example,
though.
--Devon
Attachment:
pgp00004.pgp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pgp00004.pgp
Type: application/octet-stream
Size: 187 bytes
Desc: "Description: PGP signature"
URL: <http://lists.dragonflybsd.org/pipermail/users/attachments/20050403/851add6e/attachment-0021.obj>
More information about the Users
mailing list