I was wondering if you could tell me when you are able to return NULL
, as the result of a function in C.
For instance int lenght()
can\'t retur
NULL
is a pointer value - or rather a null-pointer value.
NULL
means that the function can't find where your pointer should point to - for example if you want to open a file, but it doesn't work your file pointer is returned as NULL
. So you can test the value of a pointer and check to see if it worked or not.
If you are writing a routine
int length()
then you could return a negative value if length is unable to read the length of whatever you send it - this would be a way of indicating an error, because normally lengths can never be negative....