lecture3 - dynamic arrays, copy constructors

lecture3 - dynamic arrays, copy constructors - Friday, Jan...

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

View Full Document Right Arrow Icon
Friday, Jan 9 th   Quick  Review of Pointers Dynamic Arrays Resource Management Part 1 Copy Constructors Note:  We’re 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! Carey’s CS31 Pointer notes:  groups.msn.com/uclacs31 lecture11-post.ppt lecture12-post.ppt lecture13-post.ppt
Background image of page 1

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

View Full DocumentRight Arrow Icon
Let’s Play…. Programming Language Inventor  Or Serial Killer See if you can guess who uses a keyboard and who uses a  chainsaw!
Background image of page 2
Every Variable has an Address You can think of the computer’s 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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
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  vomit’s  address in memory? int main(void) {     int     vomit  = 15;     char  booger  = ‘B’; vomit 15 booger 66 What about  booger’s  address?
Background image of page 4
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 << “vomit’s address: “<<  & vomit<<endl;     cout << “booger’s address: “ <<  & booger; } If you place an  &  before a variable in your program, it means “ give me the  numerical address of the variable .” Output: vomit’s address: 1006 booger’s address: 1011 MEMORY
Background image of page 5

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

View Full DocumentRight Arrow Icon
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 . 100 De Neve  Westwood, CA
Background image of page 6
Defining a Pointer Variable pointer variable  is a variable that holds an  address  rather than a normal  int float double  or  string  value.       You can set a pointer variable     equal to another variable’s address: int main(void) {    short     Jennifer;     pointer    blackBook;        blackBook = &Jennifer;        . ..
Background image of page 7

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

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

Page1 / 68

lecture3 - dynamic arrays, copy constructors - Friday, Jan...

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