NULL integer ?

Hi,

the question is probably stupid, but i would like to ask is there any case an integer to be null ?

If yes, how do we examine that?

I mean we have to use something like the code below :

1
2
3
4
5
6
int A;
if(A == NULL){
    //do something
}else{
    //do something else
}
as i know NULL is defined 0 .... i mean somewhere in header files is written

#define NULL 0

...so if (A==NULL) is if (A == 0)
There is no "NULL" for integers.

The NULL is a special value because it is not a valid pointer value. Hence, we can use it as a semaphore to indicate that "this pointer does not point to anything (valid)".

All values in an integer are valid, unless your code assumes otherwise.

For example, the std::string::npos value is the largest integer value. It is special because no string can (supposedly) get that long (and be useful).

You can either choose a special value that you will not consider valid, or you can use another boolean variable to track whether or not the integer has meaning.

Hope this helps.
Topic archived. No new replies allowed.