c++ - char* a[100]是什么意思?
高洛峰
高洛峰 2017-04-17 15:23:51
0
3
1538

是存放100个字符串的数组吗?

//通过
char* binary[100] = { "0", "00", "01", "10", "000", "001", "010", "011", "100",
        "101", "110" };
//出错
char* binary[10] = { "0", "00", "01", "10", "000", "001", "010", "011", "100",
        "101", "110" };

上面就不会出错,而下面就会出错,为什么?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
大家讲道理

is an array of pointers.
Each element in the array is of type char*, pointing to the first address of each string respectively.
The following array elements have more than 10 elements.

黄舟
你的代码表示的意思是声明一个长度为n的,类型为char *的数组。这些数组的内容就是你声明这些char型字符的地址。下面为在VC6.0下编译的结果


error C2078: too many initializers
The error is that there are too many initialization contents, because the length you declared is 10, and there are 11 contents in your initialization , this will cause the array to go out of bounds, so it cannot be compiled. However, because 100>11, the second line can be compiled and passed.
Modified

伊谢尔伦

To put it simply, your code generates a two-dimensional array of char type. The first dimension is 10 and the second dimension is any length, which is char[10][]
So your program below is An error is reported if the length of one dimension exceeds 10

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!