This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14137|Reply: 0

[C] Use the pointer variable as a real parameter, and input the keyboard in reverse order

[Copy link]
Posted on 12/11/2015 11:06:54 AM | | |
//用指针变量做实参,逆序输出

#include "stdafx.h"
#include "stdio.h"
int main()
{void inv(int *x,int n);
int i,arr[10],*p=arr; Pointer variable P points to arr[0]
printf("the orginal array:\n");
for(i=0; i<10; i++,p++)
scanf("%d",p);
printf("\n");
p=arr;   Pointer variable P repoints to arr[0]
inv(p,10); Call the INV function with the real parameter P pointer variable
printf("the array has inverted:\n");
for(p=arr; p<arr+10; p++)
printf("%d,",*p);
printf("\n");
return 0;
}
void inv(int *x,int n) // Define the INV function, the parameter X pointer variable
{int *p,m,temp,*i,*j;
m=(n-1)/2;
i=x; j=x+n-1; p=x+m;
for(; i<=p; i++,j--)
{temp=*i; *i=*j; *j=temp; }

return;

}




Previous:【ios development series tutorial released in the summer】Cocos2diPhone game production
Next:Seeing you working so hard, I want to pick up the previous books and study
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com