当前位置:网站首页>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 
边栏推荐
- 程序员上班摸鱼,这么玩才高端!
- 一度辍学的数学差生,获得今年菲尔兹奖
- 九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」
- Oracle - views and sequences
- Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"
- ESG Global Leaders Summit | Intel Wang Rui: coping with global climate challenges with the power of science and technology
- 谈谈讲清楚这件事的重要性
- 什么是Web3
- JS input and output
- [hand torn STL] list
猜你喜欢

Case reward: Intel brings many partners to promote the innovation and development of multi domain AI industry

树与图的深度优先遍历模版原理

R language principal component PCA, factor analysis, clustering analysis of regional economy analysis of Chongqing Economic Indicators

Oracle - views and sequences

Chapter 9 Yunji datacanvas was rated as 36 krypton "the hard core technology enterprise most concerned by investors"

深入解析Kubebuilder

Markdown编辑器

Programmers go to work fishing, so play high-end!

当 Knative 遇见 WebAssembly

What if win11 pictures cannot be opened? Repair method of win11 unable to open pictures
随机推荐
Up to 5million per person per year! Choose people instead of projects, focus on basic scientific research, and scientists dominate the "new cornerstone" funded by Tencent to start the application
JS variable plus
Fiance donated 500million dollars to female PI, so that she didn't need to apply for projects, recruited 150 scientists, and did scientific research at ease!
Organize five stages of actual attack and defense drill
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
微信能开小号了,拼多多“砍一刀”被判侵权,字节VR设备出货量全球第二,今日更多大新闻在此
一图看懂!为什么学校教了你Coding但还是不会的原因...
使用Thread类和Runnable接口实现多线程的区别
This "advanced" technology design 15 years ago makes CPU shine in AI reasoning
Local tool [Navicat] connects to remote [MySQL] operation
Factor analysis r practice (with R installation tutorial and code)
3GPP信道模型路损基础知识
AI landing new question type RPA + AI =?
深入解析Kubebuilder
Two divs are on the same line, and the two divs do not wrap "recommended collection"
File upload vulnerability summary
两个div在同一行,两个div不换行「建议收藏」
Leetcode notes
赠票速抢|行业大咖纵论软件的质量与效能 QECon大会来啦
leetcode 53. Maximum Subarray 最大子数组和(中等)