当前位置:网站首页>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
边栏推荐
- sscanf,sscanf_ S and its related usage "suggested collection"
- Flex layout and usage
- 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
- [practice leads to truth] is the introduction of import and require really the same as what is said on the Internet
- AttributeError: module ‘torch._C‘ has no attribute ‘_cuda_setDevice‘
- mpf2_ Linear programming_ CAPM_ sharpe_ Arbitrage Pricin_ Inversion Gauss Jordan_ Statsmodel_ Pulp_ pLU_ Cholesky_ QR_ Jacobi
- File upload vulnerability summary
- If you ask me about R code debugging, I will tell you head, STR, help
- 计数排序基础思路
- jvm是什么?jvm调优有哪些目的?
猜你喜欢
Local tool [Navicat] connects to remote [MySQL] operation
A detailed explanation of head pose estimation [collect good articles]
【Android Kotlin协程】利用CoroutineContext实现网络请求失败后重试逻辑
A simple and beautiful regression table is produced in one line of code~
C语言中函数指针与指针函数
JS variable plus
In depth analysis of kubebuilder
acwing 843. n-皇后问题
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
What about the collapse of win11 playing pubg? Solution to win11 Jedi survival crash
随机推荐
Basic idea of counting and sorting
STM32 system timer flashing LED
Tiktok may launch an independent grass planting community platform: will it become the second little red book
Complimentary tickets quick grab | industry bigwigs talk about the quality and efficiency of software qecon conference is coming
A line of R code draws the population pyramid
Introduction to the PureMVC series
什么是Web3
深入解析Kubebuilder
System framework of PureMVC
Structure actual training camp | after class homework | module 6
Factor analysis r practice (with R installation tutorial and code)
MySQL数据库(基础篇)
窗口可不是什么便宜的东西
Oracle - views and sequences
【实践出真理】import和require的引入方式真的和网上说的一样吗
If you ask me about R code debugging, I will tell you head, STR, help
What if the win11 screenshot key cannot be used? Solution to the failure of win11 screenshot key
Web3 社区中使用的术语
A simple and beautiful regression table is produced in one line of code~
为什么很多人对技术债务产生误解