当前位置:网站首页>指针引用数组元素
指针引用数组元素
2022-06-29 06:40:00 【Mertrix_ITCH】
一、小结
1.一维数组:(eg:int a[5],*p;)
a+nIIp+n---->表示数组元素a[n]的地址;
(a+n)II(p+n)---->表示数组中第n个元素;
2.二维数组(int a[3][5],p;)
&a[i][j]=(a+i)+j; //表示第i行第j列元素的地址;
a[i][j]=((a+i)+j)=*(a[i]+j) //示第i行第j列元素;
//输出二维数组中的指定行数
#include<stdio.h>
int main(){
int a[3][5],i,j;
int (*p)[5]; //定义长度为5的指针型数组
p=&a[0]; //取第0行的首地址
printf("please input:\n");
for(i=0;i<3;i++){
for(j=0;j<5;j++){
scanf("%d",(*(p+i))+j);
}
}
p=&a[2];
printf("the trird line:\n");
for(j=0;j<5;j++){
printf("%5d",*((*p)+j));
}
printf("\n");
}码片
Plus (`・ω・´) 补充案例
二、二维数组元素的引用
1.((a+i)+j)-------->表示第i行,第j列的元素。
2.*(a[i]+j) --------->表示第i行,第j列的元素。
#include<stdio.h>
int main(){
int a[3][5],i,j;
printf("please input:\n");
for(i=0;i<3;i++){
for(j=0;j<5;j++){
//对i行j列的元素赋值
//scanf("%d",*(a+i)+j);
scanf("%d",a[i]+j);
}
}
printf("The second line is:\n");
for(j=0;j<5;j++){
printf("%5d",*(*(a+1)+j)); //输出第二行中的元素
//printf("%5d",*(a[1]+j));
}
printf("\n");
}
三、字符串与指针
==访问字符串 ==
1.用字符数组存放并进行操作;
2.使用字符指针指向字符串;
#include<stdio.h>
main(){
int i;
char *month[]={
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
for(i=0;i<12;i++){
printf("%s\n",month[i]);
}
}
边栏推荐
- 关于工作方法和高效工作的建议
- Dump (cl\alv\tree\base================================cp|set\items\for\column) when expanding node or clicking toolbar button
- 719. 找出第 K 小的数对距离(二分)
- 施努卡:视觉定位系统厂家 什么是视觉定位系统
- 并发幂等性防抖
- Use of LSTM neural network and general neural network
- Check whether tensorflow supports GPU and test program
- What you should know about databases
- Markdown skill tree (8): code blocks
- TREE ALV 展开Node或者点击Toolbar按钮时DUMP(CL_ALV_TREE_BASE==============CP|SET_ITEMS_FOR_COLUMN)
猜你喜欢

【工控老马】PLC六路抢答器系统设计详解
![[industrial control old horse] detailed design of PLC six way responder system](/img/9c/8bfe336bb95a028a4fb8130941ff81.png)
[industrial control old horse] detailed design of PLC six way responder system

详解Autosar Arxml中的CANFD报文及格式

Kingbasees v8r6 cluster maintenance case -- single instance data migration to cluster case

Imx6dl4.1.15 supports EIM bus (upper) - actual operation and modification.
What tools do testers need to know

Appium自动化测试基础 — ADB常用命令(二)

Reflection modification final
![[popular science materials] materials from scientific spirit to scientific knowledge](/img/fc/647805056c8ff2b30e894a6e6c4a36.jpg)
[popular science materials] materials from scientific spirit to scientific knowledge

Matlab Simulink simulation and analysis of power grid sweep frequency
随机推荐
[industrial control old horse] detailed explanation of design principle of pattern fountain based on PLC
cv2.cvtColor
How to view software testing training? Do you need training?
蓝桥杯——13届第二批试题解析
[popular science materials] materials from scientific spirit to scientific knowledge
【工控老马】西门子PLC s7-300SCL编程详解
Vibration signal generation and processing based on MATLAB Doppler effect
Kingbasees coping with transaction rollback caused by too fast growth of table age
Imx6dl4.1.15 supports EIM bus (Part 2) - configuration principle analysis.
施努卡:3d视觉检测方案 3d视觉检测应用行业
tf. compat. v1.global_ variables
Use of parameter in Simulink for AUTOSAR SWC
Markdown skill tree (4): link
Suggestions on working methods and efficient work
Using cdockablepane to realize floating window in MFC
Two ways to write throttling - recently seen
systemd 管理node-exporter
Viewing application and installation of Hana database license
Markdown skill tree (6): List
What is a Test Architect