指针例题1
作者:互联网
1 #include <stdio.h> 2 void minmax(int *a, int len, int *min, int *max); 3 int main(void) 4 { 5 int a[] = { 6 1, 7 2, 8 3, 9 4, 10 5, 11 6, 12 7, 13 8, 14 9, 15 12, 16 13, 17 14, 18 16, 19 17, 20 21, 21 23, 22 55, 23 }; 24 int min, max; 25 printf("main sizeof(a) = %d\n", sizeof(a)); 26 printf("main a = %p\n", a); 27 minmax(a, sizeof(a) / sizeof(a[0]), &min, &max); 28 printf("a[0] = %d\n", a[0]); 29 printf("min = %d, max = %d\n", min, max); 30 int *p = &min; 31 printf("*p = %d\n", *p); 32 printf("p[0] = %d\n", p[0]); 33 printf("*a = %d\n", *a); 34 return 0; 35 } 36 void minmax(int *a, int len, int *min, int *max) 37 { 38 printf("minmax sizeof(a) = %d\n", sizeof(a)); 39 printf("main a = %p\n", a); 40 a[0] = 1000; 41 *min = *max = a[0]; 42 for (int i = 1; i < len; i++) 43 { 44 if (a[i] < *min) 45 { 46 *min = a[i]; 47 } 48 if (a[i] > *max) 49 { 50 *max = a[i]; 51 } 52 } 53 }
标签:min,int,max,printf,minmax,sizeof,例题,指针 来源: https://www.cnblogs.com/2018jason/p/12054502.html