taks1
1 #include <stdio.h> 2 #define N 4 3 4 void test1() { 5 int a[N] = {1, 9, 8, 4}; 6 int i; 7 8 // 输出数组a占用的内存字节数 9 printf("sizeof(a) = %d\n", sizeof(a)); 10 11 // 输出int类型数组a中每个元素的地址、值 12 for (i = 0; i < N; ++i) 13 printf("%p: %d\n", &a[i], a[i]); 14 15 // 输出数组名a对应的值 16 printf("a = %p\n", a); 17 } 18 19 void test2() { 20 char b[N] = {'1', '9', '8', '4'}; 21 int i; 22 23 // 输出数组b占用的内存字节数 24 printf("sizeof(b) = %d\n", sizeof(b)); 25 26 // 输出char类型数组b中每个元素的地址、值 27 for (i = 0; i < N; ++i) 28 printf("%p: %c\n", &b[i], b[i]); 29 30 // 输出数组名b对应的值 31 printf("b = %p\n", b); 32 } 33 34 int main() { 35 printf("测试1: int类型一维数组\n"); 36 test1(); 37 38 printf("\n测试2: char类型一维数组\n"); 39 test2(); 40 41 return 0; 42 }
task2
标签:输出,int,char,实验,数组,printf,sizeof From: https://www.cnblogs.com/sand-bule/p/17829367.html