我有一个关于 C 语言文字的问题。
int a;
//a is an integer that is assigned an integer literal 414
a = 414;
float b;
//b is a float that is assigned a float literal of 3.14
b = 3.14;
struct point {
int x,y;
};
struct point b;
//{5,6} is a compound literal that is assigned to a struture.
b = {5,6}; //doesn't work.
b = (struct point){5,6}; //works.
如果没有类型转换,这似乎不起作用?这是什么原因呢?
(struct point){5,6}
作为一个整体是一个复合文字。
C11 §6.5.2.5复合文字
由带括号的类型名称后跟大括号括起来的后缀表达式
初始值设定项列表是复合文字。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)