-1

In c language. What happens when we subtract Null pointer from char *

int i = (char *)a - (char *)0;
iobloxx
  • 33
  • 4

1 Answers1

1

Pointer difference is defined only for two pointers that both point into or just past the end of the same array (where a pointer to a non-array object is considered as if it were a pointer to a one-element array). By definition, a null pointer does not point to any object, therefore no pointer difference involving a null pointer has defined behavior. Not even the difference between two null pointers.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157