Structs in C++

Here is an example program:

struct database {
int id_number;
int age;
float salary;

int main()
database employee; //There is now an employee variable that has modifiable
// variables inside it.
employee.age = 22;
employee.id_number = 1;
employee.salary = 12000.21;

Struct with Pointers.
A quick example:


using namespace std;

struct xampl {
int x;

int main()
xampl structure;
xampl *ptr;

structure.x = 12;
ptr = &structure; // Yes, you need the & when dealing with structures
// and using pointers to them
cout<< ptr->x; // The -> acts somewhat like the * when used with pointers
// It says, get whatever is at that memory address
// Not "get what that memory address is"

Be the first to comment

Leave a Reply