1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <stdio.h>
void prt1(int v) { printf("方法内执行后的结果:%d\n",v); } void prt2(int v[],short int len) { for (int i=0; i<len; i++) { printf("a[%d]:%d\n",i,v[i]); } } void ch1(int v) { ++v; prt1(v); } void ch2(int *v) { ++(*v); prt1(*v); }
void ch4(int v[],short int len) { for (int i=0; i<len; i++) { v[i]++; } } void test1(int v) { printf("测试单个值:类型:int,值为:%d\n",v); ch1(v); printf("执行ch1()的结果:%d\n",v); ch2(&v); printf("执行ch2()的结果:%d\n\n",v); } void test2(int v[],short int len) { printf("测试数组:类型:int,值为:\n"); prt2(v, len); ch4(v,len); printf("方法内执行后的结果:\n"); prt2(v, len); printf("\n"); } int main(int argc, const char * argv[]) { int a = 10; int b[] = {1,2,3}; test1(a); test2(b, 3); test1(b[0]); return 0; }
|