What is the difference between NULL, '\0' and 0?

前端 未结 11 1276
無奈伤痛
無奈伤痛 2020-11-21 16:32

In C, there appear to be differences between various values of zero -- NULL, NUL and 0.

I know that the ASCII character

11条回答
  •  后悔当初
    2020-11-21 17:00

    One good piece which helps me when starting with C(Taken from the Expert C Programming by Linden)

    The One 'l' nul and the Two 'l' null

    Memorize this little rhyme to recall the correct terminology for pointers and ASCII zero:

    The one "l" NUL ends an ASCII string,
    
    The two "l" NULL points to no thing.
    
    Apologies to Ogden Nash, but the three "l" nulll means check your spelling. 
    

    The ASCII character with the bit pattern of zero is termed a "NUL". The special pointer value that means the pointer points nowhere is "NULL". The two terms are not interchangeable in meaning.

提交回复
热议问题