指针数组与数组指针
来源:互联网 发布:河北大学网络教育招生 编辑:程序博客网 时间:2024/06/06 17:58
#include <stdio.h>#include <stdlib.h>/* * @brief 演示的是如何打印指针数组元素 * @param() * @return void */void printPointerArrayElems(){ //指针数组,管理地址,按照顺序执行指令 char* str[3] = {"notepad", "calc", "ipconfig"}; for (char**p = str; p < str+3; p++)//一维数组等价一级指针 { printf("%s\n", *p); system(*p); } system("pause");}//内存模型分析:notepad等字符串存储在字符常量区,str[i]存储在栈上,存储内容是字符串的首地址//p指向str[i],*p指向字符串首地址,printf("%s\n", *p);即可打印字符串/* * @brief 1.基类型概念:通过地址间接引用的数据类型为地址的基类型 * @param() * @return void */void baseType(){ int i = 9; int *p1 = &i; double j = 2; double *p2 = &j; printf("%d,%d\n", sizeof(p1), sizeof(p2)); printf("指针变量p1基类型为%d,指针变量p2基类型为:%d\n", sizeof(*p1), sizeof(*p2)); system("pause");}/* * @brief 1.二维数组中的应用 * @param() * @return void */void twoDimensionalArraybaseType(){ char str[3][10] = { "notepad", "calc", "ipconfig"}; printf("行地址:%p\n二维数组地址:%p\n二维数组[0][0]元素地址:%p\n", str,&str,*str); printf("str基类型大小:%-d\n&str基类型大小:%-d\n*str基类型大小:%-d\n", sizeof(*str), sizeof(*(&str)), sizeof(**str));//str基类型大小为10,二级指针p基类型大小为4,步长不一样。 //根据打印的指针的基类型大小反推出指针指向的内容 printf("%s\n",str); printf("%c\n",**str);}/* * @brief 演示的是如何打印数组指针元素 * @param() * @return void */void printArrayPointerElems(){ char str[3][10] = { "notepad", "calc", "ipconfig"}; for (char(*p)[10] = str; p < str +3; p++) { printf("%s\n",p);//字符型指针,%s打印的是当前地址开始以\0结束的字符串 printf("%c\n",**p); system(*p); } /*for (char**p = str; p < str+3; p++)//一维数组等价一级指针 { //指针基类型不一样,进行加减运算时步长不一样,所以运行时候会出错。 system(*p); }*/ }void main(){ printPointerArrayElems(); printArrayPointerElems(); system("pause");}
0 0
- 指针:指针与数组
- 指针与指针数组
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组与数组指针
- 数组指针与指针数组
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组与数组指针
- 指针数组 与数组指针
- 指针数组与数组指针
- 数组指针与指针数组
- 指针数组与数组指针
- 指针数组与数组指针
- 一种Unity2D多分辨率屏幕适配方案
- arm交叉编译libidn
- js动态添加节点到兄弟节点
- OracleXENuiv,数据库创建用户,表空间,
- LintCode Majority Number 主元素
- 指针数组与数组指针
- 2012年5月SAT香港真题解析
- linux根目录文件夹介绍
- NYOJ 298-点的变换(经典矩阵解决点平移、缩放、翻转和旋转)
- 黑马程序员——集合框架
- Debian系统升级:从Wheezy到Jessie
- 互联网金融机构最高补贴2000万元
- lib和dll文件的区别和联系
- Redis主从配置相关脚本