//============================================================================ // Name : Pointers.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include "Student.h" #include using namespace std; void fun1(int *q) { *q = 34; } int main() { int *g, *q;//example to show why pointers are dangerous g = new int; *g = 5; cout << g << " " <<*g << endl; delete g;//mark memory as unused // g = 0;//set g to null q = new int;//allocate new memory: this uses the same memory as g if g not set to null cout << q << " " << *q << endl; *q = 50; cout << *g << endl; *g = 10 - *q; cout << q << " " << *q << endl; //*g = 5;//illegal memory access //some older code, uncomment to see how it works... /* Student dru; dru.gpa = 4.0; cout << dru.gpa << endl; Student *studentPtr; studentPtr = &dru; (*studentPtr).gpa = 3.5; cout << dru.gpa << endl; studentPtr->gpa = 3.9; cout << studentPtr->gpa << endl; int x = 50; int *p; p = &x; cout << "X is: " << x << endl << "Address of X: " << &x << endl << "P is: " << p << endl << "Address of P: " << &p << endl << "Value of variable to which P is pointing: " << *p <