# Compare to ZERO

**URL:** <https://forum.sierrawireless.com/t/compare-to-zero/1248>\
**Category:** Development tools\
**Created:** [April 8, 2007, 9:54am UTC](https://forum.sierrawireless.com/t/compare-to-zero/1248 "2007-04-08T09:54:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![atingenieria](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@atingenieria](https://forum.sierrawireless.com/u/atingenieria)\
**Post date:** [April 8, 2007, 9:54am UTC](https://forum.sierrawireless.com/t/compare-to-zero/1248/1 "2007-04-08T09:54:09Z")

</div>

Which are the differences?

number;  
if number==‘0’;  
if number==0;  
if number==NULL;

Which type of variable has to be ‘number’?

---

<div class="post-metadata">

**Author:** ![OpenAT\_Fan](https://avatars.discourse-cdn.com/v4/letter/o/f07891/32.png) [@OpenAT\_Fan](https://forum.sierrawireless.com/u/OpenAT_Fan)\
**Post date:** [April 10, 2007, 4:20am UTC](https://forum.sierrawireless.com/t/compare-to-zero/1248/2 "2007-04-10T04:20:25Z")

</div>

Hi Atingenieria,

1. The statement, (number==‘0’) compares the value contained in the variable “number” with the ascii value of zero. As you are using C programming, you can use any datatype for “number” and use the typecasting to cast it to character to perform the comparison.
2. The statement, (number==0), compares, the value contained in the variable “number” with zero. In this case, also, the datatype can be anything and if the compilation gives you problem, you can typecast number to int and then perform the compilation.
3. The statement, (number==NULL) also compares the value contained in number with 0. (Note that NULL is internally defined as 0). Hence, this is the same as the statement (number==0).

Hope this clarifies.

Best Regards,  
Open AT Fan.

---

<div class="post-metadata">

**Author:** ![tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tobias](https://forum.sierrawireless.com/u/tobias)\
**Post date:** [April 10, 2007, 6:23am UTC](https://forum.sierrawireless.com/t/compare-to-zero/1248/3 "2007-04-10T06:23:47Z")

</div>

> [@OpenAT\_Fan](#):
>
> 1. The statement, (number==NULL) also compares the value contained in number with 0. (Note that NULL is internally defined as 0). Hence, this is the same as the statement (number==0).

Actually, NULL is defined as ((void \*)0) (pointer to 0) by ANSI C. Good practice is to only compare with NULL if you are working with pointers.

In C++ NULL can be defined as simply 0 or 0L but not ((void \*)0) and should supposedly not be used anyway. I prefer C.
