数据类型和结构

dub*_*bya 1 c++ struct types

我正在复习测试,我被这个问题困扰了.

请考虑以下声明:

enum CategoryType {HUMANITIES, SOCIALSCIENCE, NATURALSCIENCE}; 
const int NUMCOURSES = 100; 
struct CourseRec 
{ 
         string courseName; 
         int courseNum; 
         CategoryType courseCategory; 
}; 
typedef CourseRec CourseList [NUMCOURSES]; 
CourseList courses; 
int index1, index2; 
Run Code Online (Sandbox Code Playgroud)
  1. 表达式[index1] .courseName [index2]的数据类型是什么?

(a)CourseList(b)CourseRec(c)string(d)char(e)none; 表达式在语法上无效

我认为答案是字符串,因为courseName是一个字符串,甚至可能是CourseRec,因为它在结构中,但答案是(d)char.为什么这是char数据类型?任何帮助是极大的赞赏.

And*_*rey 8

让我们一步一步走:

课程[index1] .courseName [index2]

  • 课程是一系列的 CourseRec
  • 课程[index1]是 CourseRec
  • 课程[index1] .courseName是 string
  • 课程[index1] .courseName [index2]是char*

* - 实际上是 char&

  • 如果`string`是`std :: string`,它实际上是`const char&`. (4认同)