小编Bla*_*den的帖子

这会泄漏内存吗?

addStudent函数和mainMenu函数是重要的两个函数.

#include <iostream>
#include <string>

using namespace std;

struct Student
{
   string name;
   string major;
   Student *p_next;
};

Student *addStudent(Student *p_students)
{
   Student *p_new_student = new Student;
   cout << "Student name: \n";
   cin >> p_new_student->name;
   cout << p_new_student->name << "'s major: \n";
   cin >> p_new_student->major;

   Student *p_place_holder = new Student;
   Student *p_all_students = new Student;
   p_all_students = p_students;
   p_place_holder = NULL;

   if (p_students == NULL) // Adds the first element to the linked list which was initialized to NULL
   { …
Run Code Online (Sandbox Code Playgroud)

c++ memory

2
推荐指数
1
解决办法
127
查看次数

标签 统计

c++ ×1

memory ×1