Answer the question
In order to leave comments, you need to log in
( sizeof) Why are there different bytes in a string created in two different ways?
#include
int main (void)
{
char array[] = "Hi";
char*Array = "Hi";
printf("\r\n%d bytes" , sizeof array);
printf("\r\n%d bytes", sizeof Array);
return 0;
}
After compilation it gives : 3 and 4 bytes.
Where did another byte come from?
Answer the question
In order to leave comments, you need to log in
char array[] = "Hi";
This is an array consisting of 3 chars, that is, its size = 3 * 1 = 3
Here Array is a pointer to a string. Its size is always the same, whether it's "Hi" or "Helllllllllllllo"
char* Array = "Hi";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question