当前位置:网站首页>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
边栏推荐
- Analyse approfondie de kubebuilder
- Oracle -- 视图与序列
- AI表现越差,获得奖金越高?纽约大学博士拿出百万重金,悬赏让大模型表现差劲的任务
- Tree map: tree view - draw covid-19 array diagram
- acwing 843. N-queen problem
- [Yugong series] go teaching course 005 variables in July 2022
- 5G VoNR+之IMS Data Channel概念
- 计数排序基础思路
- 【数模】Matlab allcycles()函数的源代码(2021a之前版本没有)
- 使用Thread类和Runnable接口实现多线程的区别
猜你喜欢
指针与数组在函数中输入实现逆序输出
mpf2_线性规划_CAPM_sharpe_Arbitrage Pricin_Inversion Gauss Jordan_Statsmodel_Pulp_pLU_Cholesky_QR_Jacobi
[line segment tree practice] recent requests + area and retrieval - array modifiable + my schedule I / III
AI landing new question type RPA + AI =?
Intel and Xinbu technology jointly build a machine vision development kit to jointly promote the transformation of industrial intelligence
Flex layout and usage
What about the collapse of win11 playing pubg? Solution to win11 Jedi survival crash
[practice leads to truth] is the introduction of import and require really the same as what is said on the Internet
Camera calibration (I): robot hand eye calibration
Windows are not cheap things
随机推荐
【數模】Matlab allcycles()函數的源代碼(2021a之前版本沒有)
C语言中函数指针与指针函数
Gpt-3 is a peer review online when it has been submitted for its own research
JS also exports Excel
Local tool [Navicat] connects to remote [MySQL] operation
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
Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market
Introduction to namespace Basics
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!
Win11 control panel shortcut key win11 multiple methods to open the control panel
Complimentary tickets quick grab | industry bigwigs talk about the quality and efficiency of software qecon conference is coming
程序员上班摸鱼,这么玩才高端!
什么是Web3
How to open win11 remote desktop connection? Five methods of win11 Remote Desktop Connection
01机器学习相关规定
史上最全学习率调整策略lr_scheduler
JS input and output
A line of R code draws the population pyramid
R language principal component PCA, factor analysis, clustering analysis of regional economy analysis of Chongqing Economic Indicators
Two methods of chromosome coordinate sequencing