GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

What is the difference between null and zero?

1 Answer

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
...