I’m confused about the type of a string literal. Is it a const char * or a const char?
I’m confused about the type of a string literal. Is it a const char
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.
It is a
const char[N](which is the same thing aschar const[N]), whereNis the length of the string plus one for the terminatingNUL(or just the length of the string if you define “length of a string” as already including theNUL).This is why you can do
sizeof("hello") - 1to get the number of characters in the string (including any embeddedNULs); if it was a pointer, it wouldn’t work because it would always be the size of pointer on your system (minus one).