指针及其指针的使用
来源:互联网 发布:ext3 windows 编辑:程序博客网 时间:2024/05/16 00:43
一、指针数组:存放指针的数组。
示例代码:
#include<stdio.h>int main(){ int a = 4; int *p = &a; int *q = NULL; int *w = NULL; int *arr[3] = { p,q,w }; printf("%d %p %p", *arr[0], arr[1], arr[2]);}
运行结果:
二、数组指针:指向数组的指针。
(1)一维数组指针
示例代码:
#include<stdio.h>int main(){ int a[3] = { 1,2,3 }; int(*p)[3] = &a; printf("%d\n", *((*p)+0)); printf("%d\n", *((*p) + 1)); return 0;}
运行结果:
(2)二维数组指针
示例代码:
#include<stdio.h>int main(){ int a[3][2] = { {1,2},{3,4},{5,6} }; int(*p)[3][2] = &a; printf("%d\n", *(*((*p)+0)+1)); printf("%d\n", *(*((*p) + 1) + 1)); return 0;}
运行结果:
三、函数指针:指向函数地址的指针
示例代码:
#include<stdio.h>void fun1(){ printf("hello world!\n");}int main(){ void(*p)() = &fun1; //函数指针的定义 (*p)(); //*先与p结合,再与函数调用符()结合 return 0;}
运行结果:
四、函数指针数组:存放函数指针的数组
示例代码:
#include<stdio.h>void fun2(){ printf("HOW are you ?\n");}void fun1(){ printf("hello world!\n");}void fun3(){ printf("I am ok!\n");}int main(){ void(*p[3])() = { &fun1,&fun2,&fun3 }; //函数指针的定义与赋值 p[0](); p[1](); p[2](); return 0;}
运行结果:
五、指向函数指针数组的指针:
示例代码:
#include<stdio.h>void fun2(){ printf("HOW are you ?\n");}void fun1(){ printf("hello world!\n");}void fun3(){ printf("I am ok!\n");}int main(){ void(*a[3])() = { &fun1,&fun2,&fun3 }; void (*(*p)[3])()=&a; //函数指针数组的指针的定义与赋值 (*(*(p)+0))(); //函数调用 (*(*(p)+1))(); //函数调用 return 0;}
运行结果:
阅读全文
0 0
- 指针及其指针的使用
- 指针的指针使用
- 二维数组的指针及其指针变量
- 引用的使用规则及其与指针的比较
- 指针的指针使用总结
- 指针的使用二级指针
- 函数指针及其的运用
- 函数指针及其的运用
- 数组指针、指针数组、指向指针的指针使用总结
- 指针(2):关于数组指针和指向数组指针的指针及其new
- 指向指针的指针的使用
- 指针的指针的实际使用例子
- 指针的安全使用
- 使用指针的规则
- 指针的安全使用
- 指针的安全使用
- FILE指针的使用
- 指针的使用
- 分布式session跨域的两种实现方式
- 简述指针数组 数组指针 函数指针 函数指针数组和函数指针数组的指针
- Leetcode 67. Add Binary
- yum初识
- ROS下遇到.gvfs删不掉及激光雷达连不上电脑问题的解决办法
- 指针及其指针的使用
- 连续序列 最大乘积解题报告
- c++中的const与指针
- Merge、ViewStub标签总结
- HDU5285:wyh2000 and pupil(二分图染色 & 贪心)
- PAT 1036. 跟奥巴马一起编程(15)
- spring入门基础
- linux下的安装mysql与遇到一些常见问题的解决方法
- java中this关键字