第30948题 单选题
以下C++代码中,对应位置的输出语句能正确打印结构体成员的是?
#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;

程序运行统计
暂无判题统计
提交0次 正确率0.00%
答案解析