指针,函数,数组之间转换:
直接记录测试代码吧
#includeusing namespace std; void hanshu(int* p_arr); //函数声明 int main() { int arr[] = { 1,3,5,7,9,2,4,6,8,10 }; //定义一个数组 hanshu(arr); cout << "***————main函数中数组的表示————***" << endl; cout << "数组的首地址: " << arr << endl; cout << "数组第一个元素: " << arr[0] << endl; cout << "数组第五个元素值: " << arr[4] << endl; cout << "***————————————————***" << endl; system("pause"); return 0; } //1、通过指针的方式是可以改变数组中的元素内容的 //2、通过指针的方式传递数组到函数中,用指针表示数组首地址 void hanshu(int * p_arr) { cout << "***————hanshu调用后的表示————***" << endl; cout << "***指针的形式,指针名=指针指向的地址" << endl; cout << "数组首地址:" << p_arr << endl; cout << "***指针的形式,*指针名=指针指向的地址存放的具体内容(解指针)" << endl; cout << "数组第一个元素:" << *p_arr << endl; //1 cout << "***将一个数组中某个元素表示出来,格式不就是:数组名[第几个元素]" << endl; cout << "数组第五个元素: " << p_arr[4] << endl; //9 cout << "***————————————————***" << endl; }
运行结果:



