C++数组与指针小结
来源:互联网 发布:上海夏易网络怎么样 编辑:程序博客网 时间:2024/04/28 18:10
1、数组指针(一个指向数组的指针)
int arr[3] = {1,2,3};
int (*p)[3] = &arr;
for(int i = 0;i<3;i++)
{
std::cout<<(*p)[i]<<std::endl;//输出指针指向的数组中的元素
}
2、指针数组(一个存放指针的数组)
int a=1,b=2,c=3;
int *parr[3] = {&a,&b,&c};
for(int i = 0;i<3;i++)
{
std::cout<<*parr[i]<<std::endl;//输出该数组中各个指针存放的值
}
3、函数指针(一个存放函数地址的指针)
void func(int val)
{
std::cout<<"this is a function..."<<std::endl;
}
void(*p)(int) = func; //函数名即为函数的地址
int val=0;
p(val);// this is a function...
4、函数指针数组(一个存放函数指针的数组)
int func(int val)
{
std::cout<<"this is a function..."<<"val="<<val<<std::endl;
return 0;
}
int(*pfunArr[3])(int) = {func,func,func}; //定义一个三个元素的函数指针数组
for(int i = 0;i<3;i++)
{
pfunArr[i](i);//运行函数指针数组中各个指针元素指向的函数
//或者:
(*pfunArr)[i](i);//val=1,2,3
}
5、二维数组做形参时函数的声明
void func(int(*arr)[3]);//即一个指向三维数组的指针
写了这么多应该发现规律了吧。。。
- 数组与指针小结
- C中数组与指针的关系小结
- C语言关于数组与指针内容小结
- 指针与数组定义小结
- C++数组与指针小结
- C语言中关于数组与指针和字符串与指针的小结
- C数组与指针
- c 指针与数组
- C 数组与指针
- C数组与指针
- 指针与数组 C
- C指针与数组
- c数组与指针
- C-数组与指针
- C指针与数组
- c指针与数组
- C-指针与数组
- C,C++ 指针数组与数组指针
- upnp协议简介(二)
- 一个产品经理眼中的云计算:前生今世和未来
- ios Location 获取坐标
- java.security.InvalidKeyException:illegal Key Size
- 创建不同类型的用户参数
- C++数组与指针小结
- android 获取包下的类
- 解决java.lang.IllegalStateException: Calling View methods on another thread than the UI thread
- 发布网站时应该把debug设置false
- Android adapter
- getRequestURL()与getQueryString()获取用户请求URL
- Intellij setup with Java configuration
- Android 性能检测整理
- 网络基本功系列:细说路由(上)