【发布时间】:2021-03-18 00:44:52
【问题描述】:
我像这样定义了一个const int 数组:
const int arr[] = { 100 , 200, 300, 400 };
现在我想将上述数组的元素之一设置为另一个数组的长度,如下所示:
char buffer[arr[3]];
但它给了我一个编译时间error:
non-constant arguments or reference to a non-constant symbol
我研究了这个This question 来解决我的问题,但我对这些问题感到困惑:
- 为什么我不能将
const数组的元素设置为另一个数组的长度? -
const数组的元素是常量还是只读的? - c 中的
const和只读 语句有什么区别?
问候!
【问题讨论】:
标签: c++ arrays c++11 constants