Re: How printf() works???????




"Richard" <devr_@xxxxxxxxx> wrote:

Richard Heathfield <rjh@xxxxxxxxxxxxxxx> writes:

sant.tarun@xxxxxxxxx said:


Hello,

I would appreciate some comments about the piece of code given below
and explanation about the result of this specified code.

int x = 20;

printf("%d %d %d",x < 30, x = 40; x > 10);


The output of these code will be :: 0 40 1

Well, it might be, once you wrap a program around it and fix the syntax
error (a semicolon instead of a comma). First, I'll explain why you might
get that output, and then I'll explain why you might not.

x < 30 is a relational expression, and all expressions have values.
Relational expressions have the value 0 if they're false, and 1 if they're
true. So x < 30 will evaluate to 0 if x is less than 30, and 1
otherwise.

It won't actually.

How do you figure? It does in standard C. If it doesn't for you,
then your compiler is broken and you should get a better one.

--
Cheers,
Robbie Hatley
lonewolf aatt well dott com
www dott well dott com slant user slant lonewolf slant


.



Relevant Pages

  • Re: How printf() works???????
    ... below and explanation about the result of this specified code. ... x < 30 is a relational expression, ... Getting something totally backwards is,of course, a mistake. ... rarer and rarer thing these days with posters like CBF riding in on ...
    (comp.lang.c)
  • Re: How printf() works???????
    ... below and explanation about the result of this specified code. ... int x = 20; ... x < 30 is a relational expression, ...
    (comp.lang.c)
  • Re: How printf() works???????
    ... and explanation about the result of this specified code. ... int x = 20; ... x < 30 is a relational expression, ...
    (comp.lang.c)