C数组的结构

Ari*_*iou 7 c struct

typedef struct Expected {

   const int number;
   const char operand;

} Expected;   

Expected array[1];
Expected e = {1, 'c'};
array[0] = e;
Run Code Online (Sandbox Code Playgroud)

我不明白为什么你不能添加这样的结构数组.我是否必须自己计算记忆中的位置?

dbu*_*ush 10

Expected声明的元素const.这意味着他们无法修改.

为了设置值,您需要在定义变量时初始化它们:

Expected array[1] = { {1, 'c'} };
Run Code Online (Sandbox Code Playgroud)

在这种情况下,您使用数组的事实并不重要.


Joh*_*ohn 5

创建结构成员const意味着您无法写入它们.删除它后,它的工作原理.

typedef struct Expected {

   int number;
   char operand;

} Expected;
Run Code Online (Sandbox Code Playgroud)