Solved

if (variable) and if (!variable)

Posted on 2001-07-26
10
279 Views
Last Modified: 2010-04-15
Hello all,

I am an (extreme) novice at C and any other kind of programming. I would like to know what do these two blocks of code do:

if (variable) {

   [some statements]

}

and

if (!variable) {

   [some statements]

}


I would also like to know what is the difference between them.

TIA
0
Comment
Question by:gfajdi
  • 7
  • 3
10 Comments
 
LVL 5

Accepted Solution

by:
scrapdog earned 50 total points
ID: 6323090
! is the boolean "not" operator


if (variable)  means:

"If the variable evaluates to 'true', then..."



if (!variable) means:

"If the variable evaluates to 'not true' (i.e. false), then..."


Nonzero values are considered 'true'.  Values that are 0 are considered 'false'.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 6323093
When you see the ! in C code, think of it as the word "not".
0
 

Author Comment

by:gfajdi
ID: 6323328
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:gfajdi
ID: 6323428
0
 

Author Comment

by:gfajdi
ID: 6323447
So in other words:

if (variable)

is the same as

if (variable != 0)


and

if (!variable)

is the same as

if (variable == 0)


am I correct
0
 

Author Comment

by:gfajdi
ID: 6323668
So in other words:

if (variable)


is the same as

if (variable != 0)


and

if (!variable)

is the same as

if (variable == 0)


Am I correct?
0
 

Author Comment

by:gfajdi
ID: 6323728
0
 

Author Comment

by:gfajdi
ID: 6323865
Sorry for that I'm having some connection problems
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 6323937
>if (variable)
>is the same as
>if (variable != 0)
>
>and
>
>if (!variable)
>is the same as
>if (variable == 0)
>
>Am I correct?

Yes, that is correct.
0
 

Author Comment

by:gfajdi
ID: 6323984
Thanks, you have answered my question, here are your well-deserved points.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question