当前位置:网站首页>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
边栏推荐
- Common methods of list and map
- 抖音或将推出独立种草社区平台:会不会成为第二个小红书
- Flex layout and usage
- 【线段树实战】最近的请求次数 + 区域和检索 - 数组可修改+我的日程安排表Ⅰ/Ⅲ
- 日常工作中程序员最讨厌哪些工作事项?
- Advertising attribution: how to measure the value of buying volume?
- What work items do programmers hate most in their daily work?
- Gpt-3 is a peer review online when it has been submitted for its own research
- 【数模】Matlab allcycles()函数的源代码(2021a之前版本没有)
- Field data acquisition and edge calculation scheme of CNC machine tools
猜你喜欢
Break the memory wall with CPU scheme? Learn from PayPal to expand the capacity of aoteng, and the volume of missed fraud transactions can be reduced to 1/30
MySQL forgot how to change the password
Markdown编辑器
Read of shell internal value command
Decorator basic learning 02
当 Knative 遇见 WebAssembly
深入解析Kubebuilder
3GPP信道模型路损基础知识
Kivy tutorial of setting the size and background of the form (tutorial includes source code)
Section 1: (3) logic chip process substrate selection
随机推荐
What if win11 pictures cannot be opened? Repair method of win11 unable to open pictures
Section 1: (3) logic chip process substrate selection
What about the collapse of win11 playing pubg? Solution to win11 Jedi survival crash
What is Web3
计数排序基础思路
关于01背包个人的一些理解
【实践出真理】import和require的引入方式真的和网上说的一样吗
过气光刻机也不能卖给中国!美国无理施压荷兰ASML,国产芯片再遭打压
装饰器基础学习02
【数模】Matlab allcycles()函数的源代码(2021a之前版本没有)
sscanf,sscanf_ S and its related usage "suggested collection"
Vscode 如何使用内置浏览器?
Kivy tutorial of setting the size and background of the form (tutorial includes source code)
acwing 843. n-皇后问题
一图看懂!为什么学校教了你Coding但还是不会的原因...
Introduction to namespace Basics
Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot microservice code analysis and dialogue experim
Servicemesh mainly solves three pain points
Code source de la fonction [analogique numérique] MATLAB allcycles () (non disponible avant 2021a)
A series of shortcut keys for jetbrain pychar