C++ giving Access violation reading location 0xCCCCCCCC with struct

0

I'm trying to create this student structure and have it display using pointers, but when I try to run it in Visual Studio it gives me this exception

Exception thrown at 0x567DD6F0 (ucrtbased.dll) in Project3.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC.

This is the code that I'm running

struct Student {
    char name[20];
    int ID = 20;
    char grade;
    myDate birthday;
    string homeTown;
};

void display(Student * sar[]) {
    for (int i = 0; i <10; i++){
    cout << sar[i]->name;
    cout << sar[i]->ID;
    }
}

int main()
{
    Student *students[10];
    display(students);
    cin.get();
    return 0;
}

I did some research on the exception and saw some links about fully declaring the pointer, but everything that I've tried hasn't worked. Is it something to do with the array of pointers that's causing the problem?

c++
asked on Stack Overflow Mar 14, 2019 by Cam3l

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0