#include <stdio.h> void fun(int *a,int n) { int i,t; for(i=0;i<n/2;i++){ t=a[i]; a[i]=a[n-1-i]; a[n-1-i]=t; } } int main(int argc,char *argv[]) { int k[10]={1,2,3,4,5,6,7,8,9,10},i; fun(k,5); for(i=2;i<8;i++) printf("%d",k[i]); printf("\n"); }
#include "stdio.h" #define N 4 void fun(int a[][N],int b[]) { int i; for(i=0;i<N;i++) b[i]=a[i][i]-a[i][N-1-i]; } int main(){ int x[N][N]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}},y[N],i; fun(x,y); for(i=0;i<N;i++) printf("%d,",y[i]); printf("\n"); }
#include "stdio.h" #define N 4 void fun(int a[][N],int b[]) { int i; for(i=0;i<N;i++) b[i]=a[i][i]-a[i][N-1-i]; } int main(){ int x[N][N]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}},y[N],i; fun(x,y); for(i=0;i<N;i++) printf("%d,",y[i]); printf("\n"); }
#include "stdio.h" int main(){ char s[]="012xy\08s34f4w2"; int i,n=0; for(i=0;s[i]!=0;i++) if(s[i]>='0'&&s[i]<='9') n++; printf("%d\n",n);
#include "stdio.h" fun(int x,int y){ static int m=0,i=2;; i+=m+1; m=i+x+y; return m; } int main(){ int j=1,m=1,k; k=fun(j,m); printf("%d\n",k); k=fun(j,m); printf("%d\n",k); } static 定义的只会赋值一次,第二次调用沿用第一次的结果
#include "stdio.h" typedef struct {int b,p;}A; void f(A c) { int j; c.b+=1; c.p+=2; } int main(){ int i; A a={1,2}; f(a); printf("%d,%d\n",a.b,a.p); } 形参对实参没有影响