"" 8 . "xxx", 4 , , ?
, name - , . - , , - , . , . , C - .
- , ( ) . :
void f(char p[]);
void f(char *p);
char s[] = {'h', 'e', 'l', 'l', 'o'};
f(s);
char t = "hello"[1];
, ( ):
char s[] = "hello";
char *t = "hello";
printf("%d", sizeof s);
printf("%d", sizeof t);
printf("%d", sizeof *t);
char *name[] = {"xxxx", "yyyy"};
printf("%p", name);
printf("%p", &name);
name, &name printf, . , :
printf("%p", name + 1);
printf("%p", &name + 1);
printf("%d", *(&name + 1) - name); // prints the length of the array
To summarize, arrays and pointers are of different types. Pointers store addresses, arrays store values of the type that they are defined for storage. In some situations, arrays evaluate at the address of their first element. That similarity ends between arrays and pointers.
source
share