楼主:
Wardyal (Wardyal)
2024-03-01 10:03:52也是不安全写法= =
我这次懂了
之前存的是
char* my_str[] = {"apple", "banana", "cat"};
存的其实不是 char 是这个 char array 的指标
所以要用 sizeof(my_str)/sizeof(char*)
不过这次存的是int
因为是 int my_ints = {1,2,3,4,5};
所以要用 sizeof(int)
假如要用同样的逻辑
我要用 sizeof(int*)
那就要用 int* my_ints = {1,2,3,4,5};
虽然感觉没啥意义就是了
作者:
JIWP (JIWP)
2024-03-01 10:12:00int* my_ints = {1,2,3,4,5}; 你这样编译应该不会过