1 | int* ptr_a, ptr_b; |
同
1 | int *ptr_a; |
相等
The right-left rule for reading C declarations
指针的加减部分
Well, the type of a pointer matters. The type of the pointer here is int. When you add to or subtract from a pointer, the amount by which you do that is multiplied by the size of the type of the pointer. In the case of our three increments, each 1 that you added was multiplied by sizeof(int)
.
Multiple indirection
1 | int a = 3; |
There is no string type in C.
1 | char str[] = "I am the Walrus"; |
This array is 16 bytes in length: 15 characters for “I am the Walrus”, plus a NUL (byte value 0) terminator. In other words, str[15]
(the last element) is 0. This is how the end of the “string” is signaled.
1 | size_t strlen(const char *str) { Note the pointer syntax here |
Note the use of pointer arithmetic and dereferencing. That’s because, despite the function’s name, there is no “string” here; there is merely a pointer to at least one character, the last one being 0.