什么方括号意味着数组初始化用C? [英] What do square brackets mean in array initialization in C?
本文介绍了什么方括号意味着数组初始化用C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
static uint8_t togglecode[256] = {
[0x3A] CAPSLOCK,
[0x45] NUMLOCK,
[0x46] SCROLLLOCK
};
什么是的意义[0x3A]
在这里?我只学会了像 INT语句[2] = {1,2};
What's the meaning of [0x3A]
here? I have only learned statements like int a[2] = {1, 2};
推荐答案
这意味着初始化的 N 的-th数组的元素。你给出的例子将意味着:
It means initialise the n-th element of the array. The example you've given will mean that:
togglecode[0x3A] == CAPSLOCK
togglecode[0x45] == NUMLOCK
togglecode[0x46] == SCROLLLOCK
这些被称为指定初始化,并且实际C99标准的一部分。然而,如果没有语法 =
不是。从该页面:
These are called "designated initializers", and are actually part of the C99 standard. However, the syntax without the =
is not. From that page:
这一个可选的语法,因为GCC 2.5这已经过时了,但GCC仍然接受是写 [指数]
元素值,没有 =
。
An alternative syntax for this which has been obsolete since GCC 2.5 but GCC still accepts is to write
[index]
before the element value, with no=
.
这篇关于什么方括号意味着数组初始化用C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文