cs31day15 Wk 8 M

# cs31day15 Wk 8 M - Pointers: 1. Another way to implement...

This preview shows pages 1–2. Sign up to view the full content.

1. Another way to implement passing by reference 2. Traverse arrays 3. Manipulate dynamic storage 4. Represent relationships in data structures double a = 3.2; p -> a[3.2] b[5.1] double b = 5.1; double* p = &a; double c = a; double d = *p; double& dd = d; // this is a reference so if d = 3.2 == dd // p = b ERROR *p = b; // assign one double to another p = &b; // assign one pointer to another *p += 4; // means *p = *p + 4; p is a pointer to a double. *p is the value at that address int k = 7; int* z = &k; cout << (k * b); // 35.7 cout << (k * p); cout << (k *p); // Error!!! you can't multiply a pointer cout << (k * *p); cout << (k**p); // 50.4 cout << (*z * *p); cout << ((*z) * (*p)); cout << * z** p; double* q; //*p = 4.2 // Undefined behavior because the pointer is NOT INITIALIZED q = p; // then q is pointing to the same thing that p is pointing to double* r = &b; // r points to b which has a value *r = *p // the value of b changes to the value of a since p points to a. if (p == r)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## cs31day15 Wk 8 M - Pointers: 1. Another way to implement...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online