// 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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.