#include #include #include int main() { int32_t len = 10; int32_t arr[len];//arr[0] 访问数组第一个元素 // clear array 清除数组 C中数组被创建时会有内存数据 for (int a = 0; a < len; a++) { arr[a] = 0; } for (int32_t i = 0; i < len; i++) { printf("index %d,and value is %d\n", i, arr[i]); } //数组初始化 int arra[] = {1, 3, 4, 5, 8, 9}; for (int i = 0; i < 6; ++i) { printf("%d\n", arra[i]); } //创建二维数组 int array[3][4]; //clear arr for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { array[i][j] = 0; } } printf("%d\n", array[1][1]); for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { printf("index(%d,%d),%d\n", i, j, array[i][j]); } } //定义初始化 int array34[3][4] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { printf("index(%d,%d),%d\n", i, j, array34[i][j]); } } //字符数组 char str[10] = {'H', 'e', 'l', 'l', 'o', '\0'};// \0 此时系统认为字符串结尾 printf("String length : %ld,and string is %s\n", strlen(str), str); memset(str, 0, 10);//字符数组清零 printf("String length : %ld,and string is %s\n", strlen(str), str); //遍历 char string[] = "Hello World"; for (int i = 0; i < 11; ++i) { printf("(index:%d)%c\n", i, string[i]); } return 0;}