Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// I know it has something to do with the pointer (dereferencing it when I assig

ID: 3643886 • Letter: #

Question

// I know it has something to do with the pointer (dereferencing it when I assign 4 to ID) because it worked if I take it out.
// Please help. I will give 5 stars for a clear answer. Thanks.

#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct studentInfo
{
string lastName, firstName;
int *ID; // pointer
double gpa;
};

int main ()
{
vector<studentInfo> student(2);

student[1].lastName = "Von Bonald";
student[1].firstName = "Ronald";
*student[1].ID = 4; // PROBLEM WITH THIS!
student[1].gpa = 3.5;

return 0;
}

Explanation / Answer

Change *student[1].ID = 4; to *(student[1].ID) = 4; or int c = 4; student[1].ID = &c; Both should work Hope it helps please rate lifesaver