COM SCI 31 Lecture Notes - Lecture 5: Memory Address

35 views3 pages
21 Nov 2017
School

Document Summary

Declare a pointer: int *ptr1; double *ptr2; string *ptr3; nullptr / null. Do not dereference this pointer int *ptr; int i; p = &i; p = nullptr; Returns the value of the object at the memory address the pointer points to. Unititialized pointers int *p; p* = 55; // error! the pointer has been given a random memory address, not. Traversing an array const int maxsize = 5; double da[maxsize]; double* p; for (double* p = da; p < da + maxsize; p++) *p = 3. 6; // dereferencing the pointer as it is incremented to assign. // every element in the array to 3. 6. Passing arrays or portions of arrays to functions. Pointer variables work like normal variables -- if they are not passed by reference or pointed to themselves ( **a ), their value will not be changed by a function. Food rice; rice. name = rice; rice. price = 2; rice. calories = 200; mylunch[0] = rice;

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents