-
Help with Structures!
I am new to the world of structures and pointers, and was trying to use a modified version of the program example given in the structures tutorial. Every time I try to run it, it crashes. Any advice?
Code:
#include <iostream>
using namespace std;
struct database
{
int id_number;
int age;
float salary;
};
int main()
{
database employee;
database *ptr,*ptr1,*ptr2;
employee.age=28;
employee.id_number=1;
employee.salary=12000.21;
cout<<ptr->age;
cout<<ptr1->id_number;
cout<<ptr2->salary;
cin.get();
}
-
You appear to have forgotten to initialise ptr, ptr1 and ptr2. You presumably want then to point to employee.
-
oh!
Oh! I see...stupid mistake on my part. Thank you very much for your help :)