以下C++代码中,结构体的语法使用完全正确的是?

ct830563 单选题 共 个子题

请阅读各选项的代码片段,选出语法完全合法、不存在编译错误的选项(默认已引入所需头文件且声明了using namespace std;)。

A
struct Student {
    int id;
    string name;
}
int main() {
    Student s = {101, "张三"};
    cout << s.name;
    return 0;
}
B
struct Student {
    int id = 101;
    string name;
};
int main() {
    cout << Student.id << endl;
    return 0;
}
C
struct Student {
    int id;
    string name;
};
int main() {
    Student s;
    s.id = 102;
    s.name = "李四";
    cout << s.name;
    return 0;
}
D
struct Student {
private:
    int id;
    string name;
};
int main() {
    Student s;
    s.id = 103;
    cout << s.id;
    return 0;
}
正在加载题目数据…
已答 /
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析
讨论
发布
登录后参与讨论 立即登录
发布讨论需先绑定并验证手机号 去绑定手机号
加载中…
我
我
回复 @
回复 @
发送
还没有人讨论,来发表第一条吧