why sizeof("") is equivalent to 1 and sizeof(NULL) is equivalent to 4 in c-language ?
why sizeof() is equivalent to 1 and sizeof(NULL) is equivalent to 4 in c-language
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A string literal is an array of characters* (with static storage), which contains all the characters in the literal along with a terminator. The size of an array is the size of the element multiplied by the number of elements in the array.
The literal
""is an array that consists of onecharwith the value0. The type ischar[1], andsizeof(char)is always one; thereforesizeof(char[1])is always one.In C,
NULLis implementation-defined, and is often((void*)0). The size of avoid*, on your particular implementation, is 4. It may be a different number depending on the platform you run on.NULLmay also expand to an integer of some type of the value 0, and you’d get the size of that instead.*A literal is not a pointer, arrays are not pointers, pointers do not play a role in this part of the question.