1. Get the address of the array no, because the array name itself is an address
#include <stdio.h>
int main(void)
{
char c = 'A';
char cs[] = "ABC";
printf("%c,%s\n",c,cs); /* 获取字符及字符数组的内容 */
printf("%p,%p,%p\n",&c,cs,&cs); /* 获取字符及字符数组的地址,cs与&cs没有区别*/
getchar();
return 0;
}
2. The address of an array element is contiguous:
#include <stdio.h>
int main (void)
{
Char cs[] = "ABC";
printf ("%p\n%p\n%p\n%p\n", CS, &cs[0], &cs[1], &cs[2]);
GetChar ();
return 0;
}
3. The address represented by the array name is the address of the first element:
#include <stdio.h>
int main(void)
{
char str[] = "ABC";
char *p1 = str;
char *p2 = &str[0];
printf("%p,%p\n",p1,p2);
getchar();
return 0;
}
4. Accessing array elements by pointer:
#include <stdio.h>
int main (void)
{
Char str[] = "ABC";
char *p = str;
printf ("%c\n", *p);
printf ("%c\n", *p+1);
printf ("%c\n", *p+2);
printf ("\ n");
printf ("%c\n", *p);
printf ("%c\n", *++p);
printf ("%c\n", *++p);
GetChar ();
return 0;
}