Solved

if (variable) and if (!variable)

Posted on 2001-07-26
10
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

636 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