当前位置:网站首页>Pointer and array are input in function to realize reverse order output
Pointer and array are input in function to realize reverse order output
2022-07-07 04:55:00 【Xiaohao programming】
Input what output what
#include <stdio.h>
void initarray(int *parr,int size)
{
int i;
for(i=0;i<size;i++)
{
printf(" Please enter the first %d Data of elements :\n",i+1);
scanf("%d",parr++);//parr That's the address ( The pointer ), You don't have to take the address anymore
}
}
void printarray(int *parr,int size)
{
int i;
for(i=0;i<size;i++)
{
printf("%d ",*parr++);// Address ( The pointer ) Value , Type it out
}
}
int main()
{
int arry[5];
int size = sizeof(arry)/sizeof(arry[0]);
initarray(arry,size);//arry The array name is the array address 、 First element address
printarray(&arry[0],size);//&arry[0] The address of the first element is the same as the above
return 0;
}
Output results
Reverse input and output
#include <stdio.h>
void initarray(int *parr,int size)
{
int i;
for(i=0;i<size;i++)
{
printf(" Please enter the first %d Data of elements :\n",i+1);
scanf("%d",parr++);//parr That's the address ( The pointer ), You don't have to take the address anymore
}
}
/* void revangearry(int *parr,int size)// Output the input data in reverse order { int i,j; int tmp; for(i=0;i<size/2;i++) { j = size-1-i; tmp = parr[i]; parr[i] = parr[j]; parr[j] = tmp; } } */
// The above function is written in another way , Closer to the writing of pointer
void revangearry(int *parr,int size)// Output the input data in reverse order
{
int i,j;
int tmp;
for(i=0;i<size/2;i++)
{
j = size-1-i;
tmp = *(parr+i);// The array address is offset directly according to the array type , It also has the same effect as the above
*(parr+i) = *(parr+j);// Address offset according to array type , The value was changed at the corresponding address
*(parr+j) = tmp;
}
}
void printarray(int *parr,int size)
{
int i;
for(i=0;i<size;i++)
{
printf("%d ",*parr++);// Address ( The pointer ) Value , Type it out
}
}
int main()
{
int arry[5];
int size = sizeof(arry)/sizeof(arry[0]);
initarray(arry,size);//arry The array name is the array address 、 First element address
revangearry(arry,size);// In reverse order
printarray(&arry[0],size);//&arry[0] The address of the first element is the same as the above
return 0;
}
Output results
边栏推荐
- 广告归因:买量如何做价值衡量?
- 3GPP信道模型路损基础知识
- What is JVM? What are the purposes of JVM tuning?
- ACL2022 | 分解的元学习小样本命名实体识别
- 什么是Web3
- Run the command once per second in Bash- Run command every second in Bash?
- Vscode automatically adds a semicolon and jumps to the next line
- 一图看懂!为什么学校教了你Coding但还是不会的原因...
- Jetson nano configures pytorch deep learning environment / / to be improved
- What if win11 pictures cannot be opened? Repair method of win11 unable to open pictures
猜你喜欢
Deeply cultivate the developer ecosystem, accelerate the innovation and development of AI industry, and Intel brings many partners together
Common Oracle SQL statements
[practice leads to truth] is the introduction of import and require really the same as what is said on the Internet
Case reward: Intel brings many partners to promote the innovation and development of multi domain AI industry
【愚公系列】2022年7月 Go教学课程 005-变量
3GPP信道模型路损基础知识
Intel David tuhy: the reason for the success of Intel aoten Technology
How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
5G VoNR+之IMS Data Channel概念
R语言主成分pca、因子分析、聚类对地区经济研究分析重庆市经济指标
随机推荐
架构实战训练营|课后作业|模块 6
Flex layout and usage
Terms used in the Web3 community
A detailed explanation of head pose estimation [collect good articles]
[line segment tree practice] recent requests + area and retrieval - array modifiable + my schedule I / III
3GPP信道模型路损基础知识
In depth analysis of kubebuilder
Field data acquisition and edge calculation scheme of CNC machine tools
日常工作中程序员最讨厌哪些工作事项?
R descriptive statistics and hypothesis testing
DFS and BFS concepts and practices +acwing 842 arranged numbers (DFS) +acwing 844 Maze walking (BFS)
Analyse approfondie de kubebuilder
使用Thread类和Runnable接口实现多线程的区别
Intel and Xinbu technology jointly build a machine vision development kit to jointly promote the transformation of industrial intelligence
深入解析Kubebuilder
Wechat can play the trumpet. Pinduoduo was found guilty of infringement. The shipment of byte VR equipment ranks second in the world. Today, more big news is here
一度辍学的数学差生,获得今年菲尔兹奖
B站大佬用我的世界搞出卷积神经网络,LeCun转发!爆肝6个月,播放破百万
How does vscade use the built-in browser?
Jetson nano配置pytorch深度学习环境//待完善