题目
DD2360/FDD3360 HT25 (appgpu25) Quiz 1: Basic knowledge
判断题
We have a C source code file named "particletest.c", where we are defining a data structure that represents the position of a particle in (X,Y,Z). The idea is to have particle variable of type Particle, that internally contains a variable position of type Position. We have declared these two structures and the particle variable as follows: ··· struct { float x, y, z; } Position; struct { struct Position position; } Particle; int main() { struct Particle particle = { 0 }; particle.position.x = 2; particle.position.y = 1; ··· } Do you consider that this code would compile correctly as it is?
选项
A.True
B.False
查看解析
标准答案
Please login to view
思路分析
First, examine what the code is actually declaring. The line 'struct { float x, y, z; } Position;' defines an anonymous struct type and then declares a variable named Position of that type. It does not create a type named Position that you can refer to as 'struct Position' later. Similarly, 'struct { struct Position position; } Particle;' declares another anonymous struct type and a variable named Particle of that type, but it......Login to view full explanation登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
类似问题
One of the issues we observed in "particletest.c" was that the declaration of a variable that references a structure must use the struct keyword as well. For instance, let us take a look at the declaration of particle: ··· struct Particle particle = { 0 }; ··· To overcome this limitation, C allows us to declare new types by using the typedef keyword. This way, we have updated "particletest.c" to make the code more elegant and readable: ··· typedef struct { float x, y, z; } Position; typedef struct { Position position; } Particle; int main() { Particle particle = { 0 }; particle.position.x = 2; particle.position.y = 1; ··· } Given the fact that we are not specifying a tag anymore in the structure, is this code still correct?
One of the issues we observed in "particletest.c" was that the declaration of a variable that references a structure must use the struct keyword as well. For instance, let us take a look at the declaration of particle: 我们在"particletest.c"中发现的一个问题是:引用结构体的变量声明必须同时使用 struct 关键字。例如,我们来看一下 particle 的声明: ··· struct Particle particle = { 0 }; ··· To overcome this limitation, C allows us to declare new types by using the typedef keyword. This way, we have updated "particletest.c" to make the code more elegant and readable: 为了克服这一限制,C 语言允许使用 typedef 关键字来声明新类型。通过这种方式,我们更新了"particletest.c"使代码更加优雅和易读: ··· typedef struct { float x, y, z; } Position; typedef struct { Position position; } Particle; int main() { Particle particle = { 0 }; particle.position.x = 2; particle.position.y = 1; ··· } Given the fact that we are not specifying a tag anymore in the structure, is this code still correct? 考虑到我们不再在结构中指定标签,这段代码仍然正确吗?
We have a C source code file named "particletest.c", where we are defining a data structure that represents the position of a particle in (X,Y,Z). The idea is to have particle variable of type Particle, that internally contains a variable position of type Position. 我们有一个名为"particletest.c"的 C 源代码文件,其中定义了一个表示粒子在(X,Y,Z)位置的数据结构。目的是创建一个类型为 Particle 的粒子变量,其内部包含一个类型为 Position 的位置变量。 We have declared these two structures and the particle variable as follows: 我们按以下方式声明了这两个结构体和粒子变量: ··· struct { float x, y, z; } Position; struct { struct Position position; } Particle; int main() { struct Particle particle = { 0 }; particle.position.x = 2; particle.position.y = 1; ··· } Do you consider that this code would compile correctly as it is? 你认为这段代码在当前状态下能正确编译吗?
What does the deck[52] array contain in the following statement? struct card a, deck[52], *cPtr;
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!