I created the following array:
char* myarr= "data successfully inserted";
when I do
sizeof(myarr)
I get 8. Why do I get that?. If 1 char is 1 byte then size of myarr should be 26 by just counting the characters right?
I created the following array:
char* myarr= "data successfully inserted";
when I do
sizeof(myarr)
I get 8. Why do I get that?. If 1 char is 1 byte then size of myarr should be 26 by just counting the characters right?
On your platform, a char
pointer is 8 bytes. That's the size of the pointer variable, not the size of whatever it's pointing to. If you want the length of a string, call strlen(myarr)
.
Because that's the size of a pointer on your system. If you want to get the length of a string, you should use strlen()
function.
sizeof(myarr)
is not the size of the string but the size of char * pointe
r on your platform which gives you 8 bytes
. the size of the array can be calculated by strlen(myarr)