Computer Science 1037A/B Lecture 4: Pointers

19 views1 pages

Document Summary

Each variable in a program is stored at a unique location in memory that has an address. Use the address operator & to get the address of a variable int num = -23; cout << &num; //prints address in hexadecimal cout << long(&num); //print address in decimal. The address of a memory location is a pointer. Pointer variable (pointer): a variable that holds an address. Pointers provide an alternate way to access memory locations. Current c++ compilers that run on pcs usually allocate: A single byte to variables of type char. 4 bytes to variables of type float and long. 8 bytes to variables of type double int *intptr; "intptr" can hold the address of an "int" The variable that "intptr" points to has type "int" The spacing in the definition does not matter: int * intptr; int* intptr; Assignment int num = 25; int *intptr; intptr = &num;

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