About null

Sep 6, 2008 at 3:13am
Sir what is null.what does it represent in c and c++? Is it a keyword or identifier ? What value does it contain ?
Sep 6, 2008 at 3:27am
I am fairly certain the standard says NULL is the following:
1
2
3
4
5
6
7
#ifndef NULL
 #ifdef __cplusplus
  #define NULL  0
 #else
  #define NULL  ((void *)0)
 #endif
#endif 

So in C++, NULL is 0, and in C NULL is 0 casted to a void pointer.
Sep 7, 2008 at 1:18am
Actually, the value of NULL is system-dependent. 0, however, is guaranteed by the standard to be an invalid pointer in any system. So 0 and NULL are equivalent (they are both invalid pointers), but NULL may not equal 0.

"When in doubt, set it to zero."
Topic archived. No new replies allowed.