简体   繁体   English

将2d数组的元素设为常量

[英]Making an element of a 2d array a constant

Suppose I have a 2d array as 假设我有一个二维数组

arr[10][15];

Now, I want just one element of the array to be constant. 现在,我只希望数组的一个元素是常量。 I want the arr[9][8] to be fixed to 101: 我希望将arr [9] [8]固定为101:

arr[9][8] = 101;

I tried this: 我尝试了这个:

const arr[9][8] = 101;

But the compiler gave errors. 但是编译器给出了错误。 How can I make it constant? 我如何使其恒定?

You can make the whole array constant, but you cannot make just part of it constant. 您可以使整个数组恒定,但不能仅使其中一部分恒定。 If part of the array is mutable, then the whole array has to be mutable. 如果数组的一部分是可变的,则整个数组必须是可变的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM