What is the difference between NULL and NUL?

NULL is a macro defined in <stddef.h> for the null pointer. NUL is the name of the first character in the ASCII character set. It corresponds to a zero value. There’s no standard macro NUL in C, but some people like to define it. The digit 0 corresponds to a value of 80, decimal. Don’t confuse the digit 0 with the value of ‘’ (NUL)! NULL can be defined as ((void*)0), NUL as ‘’.  

Showing Answers 1 - 1 of 1 Answers

abhimanipal

  • Jan 30th, 2010
 

When we have a pointer variable of the sort
char* p

We often want to initialize it to 0, to ensure it does not point anywhere. We do this by
char* p=0

Many programmers do not feel comfortable with the fact that 0 has to meanings in the program. The decimal number 0 and the adress 0. So we achieve the above by writing
char* p= NULL

NULL is defined in the header files and is represented as ((void*)0)

NUL character is a character which has ACII value 0. It is used to indicate the end of the string.

So in a nutshell NULL is an address and NUl is a character.
To prove my point run this example

int main(int argc, char* argv[])
{
        printf("%d %dn",sizeof(''),sizeof(NULL));
}

More information can be found here

http://en.wikipedia.org/wiki/Null_character

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions