Re: How printf() works???????
- From: Richard <devr_@xxxxxxxxx>
- Date: Fri, 07 Mar 2008 13:44:43 +0100
santosh <santosh.k83@xxxxxxxxx> writes:
Robbie Hatley wrote:
"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.
The expression x < 30 will evaluate to 1 if x is less than 30 and zero
otherwise. Richard said the reverse, by mistake I'm sure.
Getting something totally backwards is,of course, a mistake. There is no
evil intent in my correction. Why you feel the need to confirm his
"mistake" is very strange. Possibly you should inform Robbie to be less
quick to tell people their compilers are broken and that they should get
a new one?
Which leads to the question "Why didn't you explain why Heathfield was
wrong". And the answer is simple : I don't believe in treating people
like idiots. Let them look and think the problem over themselves. They
can always come back and say "you have me stumped", what is the issue?".
A good C programmer and "team player" thinks for themselves. RH had said
enough about the comparison expression for anyone with half a clue to
see why he had made a mistake in his final analysis.
But of course, giving credence and credit to other posters is becoming a
rarer and rarer thing these days with posters like CBF riding in on
their chargers at a moments notice.
People in clc are far too eager to see other people wrong so that they
can score some clique points by being rude and obnoxious at the first
possible point. See the races to post OT rejoinders for a good example -
when they KNOW that Default User or CBF have already beaten them to it.
It's why I come here to be honest. It's fun to watch and relieves the
boredom of a typical C programming day. And one learns something here -
not always standard C related either. Fortunately there are more posters
willing to "break topicality" and, err, talk about real C.
.
- Follow-Ups:
- Re: How printf() works???????
- From: santosh
- Re: How printf() works???????
- From: Richard Heathfield
- Re: How printf() works???????
- References:
- How printf() works???????
- From: sant . tarun
- Re: How printf() works???????
- From: Richard Heathfield
- Re: How printf() works???????
- From: Richard
- Re: How printf() works???????
- From: Robbie Hatley
- Re: How printf() works???????
- From: santosh
- How printf() works???????
- Prev by Date: Re: predict the answer
- Next by Date: Re: How printf() works???????
- Previous by thread: Re: How printf() works???????
- Next by thread: Re: How printf() works???????
- Index(es):
Relevant Pages
|