Ask a Question

 

Start Coding Today

   

GeeksQuiz

GeeksforGeeksIDE

Data Structures

Algorithms

Interview Experiences

C Programming

C++ Programming

Java Programming

GATE CS

Books

What is the difference between null and zero?

asked Dec 13, 2015 by passion34

1 Answer

0 votes

In programming context, Null is defined as  (void*) 0 so,  zero and null both have the same value (0)

in them but zero is of integer type and null is of pointer type. In most cases they can be used interchangeably because compiler automatically typecasts the values to required form.

for example if you write p = NULL;   the pointer actually points to nowhere and assignment is correct

but when you write p = 0; then 0 is typecasted to pointer p's type which essentially mean the same thing as above.

so you can use both of them most of the places but you should avoid internal typecasting for more readability of code.

answered Dec 13, 2015 by utkarsh111

Please log in or register to answer this question.

...