指针与数组的关系是什么啊
1、指针:系统为某一个变量开辟单元格,指针便指向此单元格的变量值。2、数组:系统为某一组数开辟一组单元格,数组首地址便是你定义的数组变量名。数组和指针的唯一区别是,不能改变数组名称指向的地址。对于数组来说,数组的首地址,也可以用指针来表示操作,如:int a[10];int *p,n;p = a;对第一个元素取值,可以用几种方法:n =a[0];n = *p;n = p[0];n = *(p+0) ;但是以下语句则是非法的:readings = totals; // 非法!不能改变 readings totals = dptr; // 非法!不能改变 totals数组名称是指针常量。不能让它们指向除了它们所代表的数组之外的任何东西。扩展资料下面的程序定义了一个 double 数组和一个 double 指针,该指针分配了数组的起始地址。随后,不仅指针符号可以与数组名称一起使用,而且下标符号也可以与指针一起使用。int main(){const int NUM_COINS = 5;double coins[NUM_COINS] = {0.05, 0.1, 0.25, 0.5, 1.0};double *doublePtr; // Pointer to a double// Assign the address of the coins array to doublePtrdoublePtr = coins;// Display the contents of the coins array// Use subscripts with the pointer!cout << setprecision (2);cout << "Here are the values in the coins array:\n";for (int count = 0; count < NUM_COINS; count++)cout << doublePtr [count] << " ";// Display the contents of the coins array again, but this time use pointer notation with the array name!cout << "\nAnd here they are again:\n";for (int count = 0; count < NUM_COINS; count++)cout << *(coins + count) << " ";cout << endl;return 0;}程序输出结果:Here are the values in the coins array: 0.05 0.1 0.25 0.5 1 And here they are again: 0.05 0.1 0.25 0.5 1当一个数组的地址分配给一个指针时,就不需要地址运算符了。由于数组的名称已经是一个地址,所以使用 & 运算符是不正确的。但是,可以使用地址运算符来获取数组中单个元素的地址。
C语言数组指针?
int (*pstu)[4]; 为指向有4个元素的数组的指针int* getPosPerson(int pos, int (*pstu)[4]); 为返回值为指针的函数注意这是指针函数,而不是函数指针,后者为指向函数的指针变量,两者含义是不同的(类似指针数组和数组指针,两者含义也是不同的,一个本质是数组,一个本质是指针)调用该函数的语句为:ppos = getPosPerson(pos, scores);传入的scores表示3行4列的二维数组首行数组的地址,即&scores[0]调用后相当于int (*pstu)[4]=scores,所以在getPosPerson中pstu与scores是等价的即pstu可看作&scores[0],那么pstu+pos也就等价于scores+pos,等价于&scores[pos]即返回了指向&scores[pos](也就是scores第pos+1行的地址)的指针返回该行指针ppos 后,就可以查看该行表示的学生的4科成绩了

