Adt lab/pointers
- This is part of adt lab.
Pointers
In C/C++, there is a special kind of types: pointers. Pointer variables keep locations in the memory. To declare a pointer variable, we use symbol *:
type* variable;
For example, the following code declares p as a pointer to an integer.
int* p;
To see how pointers work, let's follow this code.
int a = 10;
int b = 20;
p = &a;
cout << (*p) << endl;
*p = 100;
cout << a << endl;
a++;
cout << (*p) << endl;
p = &b;
a = *p;
cout << a << endl;