473,756 Members | 3,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on an "if" statement on a numerical value

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
3 1591
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
sa******@hotmai l.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
Thanks!

- Sapn

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
10899
by: Scott Beavers | last post by:
I'm trying to create a form in Excel to sort from the form and take the data to another worksheet. I am very new to this and any help would be appreciated. I have a value in a cell that will direct what sheet I want the cells copied to, so I thought I could use an If statement but have been unable to right the code properly, ie... If "f2" = 1 Then Sheets("XX1").Select
3
1765
by: Chris Tilley - HPC:Factor | last post by:
Hi, I'm utterly confounded by this one. There must be some sort of rule that I don't know of. I'd consider myself a Newbie+1, so be gentle. I have a database connection (working A-Ok) and a Query String value from a form (passed using GET & working Ok). The server is IIS5. What I'm trying to do is get a simple IF statement to work accross the two numeric values. Once from a database and one from a Query String.
1
66870
by: M Wells | last post by:
Hi All, Just wondering if anyone can tell me if you can test for multiple conditions as part of an "IF" statement in T-SQL in SQL Server 2000? ie something like: IF @merr = 1 or @merr=2 Begin SELECT statement
6
2268
by: JS | last post by:
In this sample code: if(n==0&&args>1){ for(i=num;args>i+1;i++){ s.length = 0; opt = document.createElement('OPTION'); s.appendChild(opt); opt.value = ""; opt.text = "\74-- Vælg --"; }
35
2733
by: David Cleaver | last post by:
Hello all, I was wondering if there were some sort of limitations on the "if" statement? I'm writing a program which needs to check a bunch of conditions all at the same time (basically). And I'm pretty sure the rest of the program is working just fine. The only thing I could think might be wrong is that the if statement can only hold so many values in itself? Let me show what I'm doing: if (table001]>>5]&b&0x1f] != 0 &&
3
29799
by: Mark Sullivan | last post by:
When I trace through a csharp program I came to a situation where a certain values has an "undefined value" as shown in the debugger DbgClr. I want to check this but the following statements did not recognize this "non"-value if (type.Particle != Undefined.Value) { .... or if (type.Particle != null) { .....
6
2379
by: Jacob.Bruxer | last post by:
Hi, I'm pretty new to Visual Basic and programming in general. I want to know if it's possible to create an If statement that asks if a value is an integer. If it's an integer it does one thing, if it's a decimal value it does something else. Something like the following... If i = integer Then ..... a.... Else ...... b .....
2
2073
by: marsarden | last post by:
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if
6
2253
by: vl106 | last post by:
A static code analysis tool gave me a warning on if (ptr && ptr->data) { ... } I assumed the tool doesn't get the "short circuit behaviour" in the if statement. But a collegue said it may be the missing check ot ptr against NULL.
9
2858
by: chutsu | last post by:
hi I got a simple program, and I was wondering how do you check if the string in an array = a string. For example if I put "APPLE" in array Array then how can I check it with a if statement. if (Array == 'APPLE'){ do something; } or do I need to use a different method to check?
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9841
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9711
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7244
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5141
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5303
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.