lecture3

lecture3 - Friday, Jan 8 th A Quick Review of Pointers...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Friday, Jan 8 th A Quick Review of Pointers Dynamic Arrays Resource Management Part 1 Copy Constructors Note: Were only reviewing about 50% of the key pointer concepts! If you feel uncomfortable with pointers, then study and become an expert before our next class! Careys CS31 Pointer notes: posted onto our website! cs31.zip: lecture11.ppt , lecture12.ppt , lecture13.ppt Lets Play. Programming Language Inventor Or Serial Killer See if you can guess who uses a keyboard and who uses a chainsaw! Every Variable has an Address You can think of the computers memory like a street with a bunch of vacant lots. Some variables occupy a single lot, while others occupy several adjacent lots. 100 101 102 103 104 MEMORY void foo(void) { short boogers = 5; char mucus = G; ... boogers 5 mucus G When you define a variable in your program, the computer finds an unused address in memory and reserves it for your variable. Variable Addresses Important : The address of a variable is defined to be the first address in memory where the variable is stored. 00000000 00000001 00001000 00001001 00001002 00001003 00001004 00001005 00001006 00001007 00001008 00001009 00001010 00001011 99999990 99999991 99999992 So, what is vomits address in memory? int main(void) { int vomit = 15; char booger = B; vomit 15 booger 66 What about boogers address? We can get the address of a variable using the & operator. Getting the Address of a Variable 01000 01001 01002 01003 01004 01005 01006 01007 01008 01009 01010 01011 vomit 15 booger B int main(void) { int vomit = 15; char booger = B; cout << vomits address: << & vomit<<endl; cout << boogers address: << & booger; } If you place an & before a variable in your program, it means give me the numerical address of the variable . Output: vomits address: 1006 boogers address: 1011 MEMORY I have an address now what? Once you get the address of a variable, what do you do with it? Well, when you ask a girl/guy for their address, what do you do with it? You write it down in your little black book! In a similar way, once we get the address of a variable, we save it in a pointer variable . 1 D e N e v e W e s t w o o d , C A Defining a Pointer Variable A pointer variable is a variable that holds an address rather than a normal int , float , double or string value....
View Full Document

Page1 / 68

lecture3 - Friday, Jan 8 th A Quick Review of Pointers...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online