By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

Help on an "if" statement on a numerical value

P: n/a
Hi folks,

I am looking at an application written in C some 10+ years ago. There
is a lot of such if statements:
if (my_number) {....} else {...}
Here, my_number is an unsigned int. What exactly is the "if" looking
for to evaluate? Is it the existence of a numerical value or a non-zero
value or just any positive value? I am not a C programmer by trade and
hence this question.

LOL,
Sapn

Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Fri, 22 Jul 2005 05:01:21 -0700, sapnsapn wrote:
I am looking at an application written in C some 10+ years ago. There is a
lot of such if statements:
if (my_number) {....} else {...}
Here, my_number is an unsigned int. What exactly is the "if" looking for
to evaluate? Is it the existence of a numerical value or a non-zero value
or just any positive value? I am not a C programmer by trade and hence
this question.


Any non-zero value.

Nov 15 '05 #2

P: n/a
sa******@hotmail.com wrote:
Hi folks,

I am looking at an application written in C some 10+ years ago. There
is a lot of such if statements:
if (my_number) {....} else {...}
Here, my_number is an unsigned int. What exactly is the "if" looking
for to evaluate? Is it the existence of a numerical value or a non-zero
value or just any positive value? I am not a C programmer by trade and
hence this question.

LOL,
Sapn


For any variable type, "if (foo)" is the same as
"if (foo != 0)"

That works for ints, pointers, chars, etc. Some (including
me) think that "if (foo)" should be only used for variables being
used as boolean, but that is a style question. I prefer being
explicit,
as in "if (foo != '\0')", or "if (foo != NULL)" or "if (foo != 0)".
But all work the same as "if (foo)".

-David

Nov 15 '05 #3

P: n/a
Thanks!

- Sapn

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.