zaPointer Lecture 1

zaPointer Lecture 1 - Monday, November 15 th • No midterm...

Info iconThis preview shows pages 1–7. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Monday, November 15 th • No midterm grades yet… • Pointers , pointers , pointers … Pointers are one of the most complex topics in C/C++. If you don’t understand pointers well, you’ll be tortured by horrible bugs , so pay attention! And now for… Pointers Every variable in C++ can be described by five different attributes: 1. every variable has a name 2. every varaible has a type 3. every variable has a size 4. every variable has a value 5. every variable has an address! int main(void) { int earwax = 3 ; ... Variable Addresses Every byte in the computer‘s memory has its own address ( just like each house on a street has an address ). … … 00000000 00000001 00001000 00001001 00001002 00001003 00001004 00001005 00001006 00001007 00001008 00001009 00001010 00001011 99999990 99999991 99999992 When you define a variable in your program, the computer finds an unused set of address in memory and reserves them for your variable. 1 byte int main(void) { int vomit = 15; char booger = ‘B’; vomit 15 booger 66 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? We can get the address of a variable using the & operator. Finding the Address of a Variable 00001000 00001001 00001002 00001003 00001004 00001005 00001006 00001007 00001008 00001009 00001010 00001011 vomit 15 booger 66 int main(void) { int vomit = 15; char booger = ‘B’; cout << “Value: “ << vomit << endl; cout << “Size: “ << sizeof(vomit) << endl; 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 .” &: It’s for References and Pointers When we place an & before a function parameter , we make the parameter a reference parameter . void booboo(int & a) { ... // a is a reference parameter. } Be careful not to confuse the two....
View Full Document

This note was uploaded on 04/02/2012 for the course COMPUTER S 32 taught by Professor Smallberg during the Winter '12 term at UCLA.

Page1 / 28

zaPointer Lecture 1 - Monday, November 15 th • No midterm...

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

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