指针作为函数的返回值

来源:互联网 发布:淘宝上阿迪的正品店铺 编辑:程序博客网 时间:2024/04/28 02:24

指针不但可以作为函数的参数进行传递,还可以作为函数的返回值,返回的指针即可以指向

任何数据类型的地址,也可以指向一维数组或者多维数组的地址


#include<iostream>using namespace std;int* getindex(int index);int main(){for (int i = 0; i < 7; i++){cout << *getindex(i) << endl;}system("pause");return 0;}int *getindex(int index){static int data[] = { 13, 57, 65, 68, 57, 47, 32 };return &data[index];}


0 0
原创粉丝点击