小编Ada*_*yne的帖子

为什么动态分配的指针数组不需要解除引用来获取实际成员

所以我最近遇到了以下代码:

struct Student
{
    int *number;
    char *name;
    double *marks;
};

int main(){
    int n;
    Student *s;
    s = new Student;
    cout << "Enter the number of subjects the student learns: ";
    cin >> n;
    s->number= new int;
    s->name=new char[20];
    s->marks=new double[n];
    cout << "Enter the name of the student: ";
    cin >> s->name;
    cout << "Enter the number in class of " << s->name << ": ";
    cin >> *(s->number);
    for (int i = 0 ; i < n …
Run Code Online (Sandbox Code Playgroud)

c++ arrays pointers dynamic-memory-allocation dereference

0
推荐指数
1
解决办法
1096
查看次数