1.2 KiB
1.2 KiB
Lecture 4 --- Pointers, Arrays, & Pointer Arithmetic
- Pointers store memory addresses.
- They can be used to access the values stored at their stored memory address.
- They can be incremented, decremented, added, and subtracted.
- Dynamic memory is accessed through pointers.
- Pointers are also the primitive mechanism underlying vector iterators, which we have used with std::sort and will use more extensively throughout the semester.
4.1 Pointer Example
- Consider the following code segment:
float x = 15.5;
float *p; /* equiv: float* p; or float * p; */
p = &x;
*p = 72;
if ( x > 20 )
cout << "Bigger\n";
else
cout << "Smaller\n";
The output is Bigger because x == 72.0. What’s going on?