The Encapsulator wrote: |
---|
Can anyone explain to me, what is the difference between NULL and '\0' (which is also referred to as NULL character)? |
'\0' is interpreted as a magic constant, which is zero. The definition of
NULL depends on the compiler. I've seen two ways
NULL was defined:
1 2 3 4
|
/* GCC: */
#define NULL 0
/* Visual C++: */
#define NULL ( ( void * )0 )
|
In the context of pointers, if the expression evaluates to zero, it pretty much means null. Of course, C++11 defines
nullptr which should be preferred.
The Encapsulator wrote: |
---|
Against this syntax char* a = NULL; the pointer of type a starts pointing towards NULL. Is there any physical existence of NULL on our main memory? |
I believe it points to the first address (0x0) in memory. Though, this will need to be confirmed. I mean, it has to point somewhere, right?
The Encapsulator wrote: |
---|
What's the difference amongst following three statements?
1 2 3
|
char *temp = NULL;
char *temp = '\0';
char *temp = "";
|
|
The first two are null, the 3
rd points to a string with 1 character - the null character. This doesn't make the pointer null.
Wazzak