W
W
Whomai2020-10-24 16:04:58
Arrays
Whomai, 2020-10-24 16:04:58

( 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

1 answer(s)
T
Timur Pokrovsky, 2020-10-24
@Whomai

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 question

Ask a Question

731 491 924 answers to any question