C语言中并没有String类型,strings in C are actually arrays of characters.
sizeof("Turtles!")
This will return 9, which is 8
characters plus the \0 end character
[b]Array variables are like pointers…[/b]
When you create an array, the array variable can be used as a pointer to the start of the array in memory.
char quote[] = "Cookies make you fat";
The computer will set aside space on the stack for each of the
characters in the string, plus the \0 end character. But it will also
associate the address of the first character with the quote
variable. Every time the quote variable is used in the code, the
computer will substitute it with the address of the first character in
the string. In fact, the array variable is just like a pointer:
drinks[0] 和*drinks 是等价的
sizeof("Turtles!")
This will return 9, which is 8
characters plus the \0 end character
[b]Array variables are like pointers…[/b]
When you create an array, the array variable can be used as a pointer to the start of the array in memory.
char quote[] = "Cookies make you fat";
The computer will set aside space on the stack for each of the
characters in the string, plus the \0 end character. But it will also
associate the address of the first character with the quote
variable. Every time the quote variable is used in the code, the
computer will substitute it with the address of the first character in
the string. In fact, the array variable is just like a pointer:
int drinks[] = {4, 2, 3};
printf("1st order: %i drinks\n", drinks[0]);
printf("1st order: %i drinks\n", *drinks);
drinks[0] 和*drinks 是等价的