Computer Science 1037A/B Lecture 4: Pointers
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 << # //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 = #