C++中关于指针数组的问题。

2025年03月01日 14:43
有2个网友回答
网友(1):

举个例子:
int x=20,y=10,*a[2];
a[0]=&x,a[1]=&y;
printf("x=%d y=%d\n",*a[0],*a[1]);
就会输出x=20 y=10
------------------
1)*a即a[0],在上例中也就是x的地址。
2)中括号[]内数字可以由编译系统自动测定初始化了几个元素,

char *p[]={"hello"}; 就相当于char *p[1]={"hello"};

char *q[]={"hello","world"}; 就相当于char *q[2]={"hello","world"};

网友(2):

*p即p[0],即数组中下表为0的元素