#GOBJ403H. GESP 4级客观题|结构体|课后作业

GESP 4级客观题|结构体|课后作业

GESP 4级客观题|结构体|课后作业

考试频率:高频。本卷共 6 题。

  1. 下⾯的描述中,( )不能正确定义⼀个名为 Student 的结构体以及⼀个包含20个元素的结构数组。
//A:
struct Student {
    string name;
    int age;
    float score;
};
struct Student  students[20];

//B:
struct Student {
    string name;
    int age;
    float score;
};
Student  students[20];

//C:
struct Student {
    string name;
    int age;
    float score;
};
Student*  students = new Student[20];

//D:
struct Student {
    string name;
    int age;
    float score;
};
Student  students = new Student[20];

{{ select(1) }}

  • A
  • B
  • C
  • D
  1. 下面C++代码在一个结构体中又定义了别的结构体。这种结构嵌套定义的方式语法不正确。
struct Library {
    struct Book {
        struct Author {
            string name;
            int birthYear;
        };
        string title;
        int year;
        Author author;
    };
    string name;
    vector<Book> books;
};

{{ select(2) }}

  1. 给定如下代码,
struct Person
{
    std::string name;
    int age;
    struct Address
    {
        std::string street;
        std::string city;
    };
    Address address;
};

下面描述错误的是( )。

{{ select(3) }}

  • 结构 Person 内嵌套结构 Address
  • Person 有一个 Address 类型的 address 成员
  • 一个 Person 类型的变量 paddress 的初始化可以写成: p.address.street = "123 Main St";p.address.city = "Anytown";
  • 结构的嵌套可以减少命名冲突,因此可以不必控制嵌套层次
  1. 结构体的成员默认是 public 访问权限。

    {{ select(4) }}

  1. 在C++语言中 try 子句里抛出的结构体等类型的异常无法被 catch 捕获。( )

    {{ select(5) }}

  1. 关于结构体初始化,以下哪个选项中正确的是( )。

    {{ select(6) }}

  • Point p = (1,2);
  • Point p = {1,2};
  • Point p = new {1,2};
  • Point p = <1,2>;
蜀ICP备2025119001号-1