以下C++代码中,对应位置的输出语句能正确打印结构体成员的是?

ew611368 单选题 共 个子题
#include <iostream>
#include <string>
using namespace std;

struct Student {
    string name;
    int age;
};

int main() {
    Student s1 = {"张三", 18};
    Student *p = &s1;
    // 下列四个输出语句中,哪一个可以正确输出s1的姓名和年龄?
    return 0;
}
A

cout << p.name << " " << p.age << endl;

B

cout << p->name << " " << p->age << endl;

C

cout << *p->name << " " << *p->age << endl;

D

cout << (p).name << " " << (p).age << endl;

正在加载题目数据…
已答 /
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析
讨论
发布
登录后参与讨论 立即登录
发布讨论需先绑定并验证手机号 去绑定手机号
加载中…
我
我
回复 @
回复 @
发送
还没有人讨论,来发表第一条吧