





























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Lecture notes for CSE333 Autumn 2018, covering the topics of references, const, and classes in C++. explanations, examples, and exercises. Students are encouraged to read the sections in C++ Primer on class constructors, copy constructors, assignment operators, and destructors before the next class.
Typology: Slides
1 / 37
This page cannot be seen from the preview
Don't miss anything!






























Administrivia v Yet another exercise released today, due Friday v Sections this week: C++ classes, references + Makefiles! § Don’t miss!! – you’ll need to create Makefiles soon, and this is the only
v More office hours added on Wed. and Thur. afternoons v Homework 2 due next Thursday (7/19) § Note: libhw1.a (yours or ours) needs to be in correct directory
§ Use Ctrl-D to exit searchshell; must free all allocated memory § Test on directory of small self-made files § Valgrind takes a long time on the full test_tree. Try using enron docs
Pointers Reminder v A pointer is a variable containing an address § Modifying the pointer doesn’t modify what it points to, but you can access/modify what it points to by dereferencing § These work the same in C and C++ int main (int argc, char** argv) { int x = 5 , y = 10 ; int* z = &x; *z += 1 ; x += 1 ; z = &y; *z += 1 ; return EXIT_SUCCESS; }
Pointers Reminder v A pointer is a variable containing an address § Modifying the pointer doesn’t modify what it points to, but you can access/modify what it points to by dereferencing § These work the same in C and C++ int main (int argc, char** argv) { int x = 5 , y = 10 ; int* z = &x; *z += 1 ; x += 1 ; z = &y; *z += 1 ; return EXIT_SUCCESS; }
Pointers Reminder v A pointer is a variable containing an address § Modifying the pointer doesn’t modify what it points to, but you can access/modify what it points to by dereferencing § These work the same in C and C++ int main (int argc, char** argv) { int x = 5 , y = 10 ; int* z = &x; *z += 1 ; // sets x to 6 x += 1 ; // sets x (and *z) to 7 z = &y; *z += 1 ; return EXIT_SUCCESS; }
Pointers Reminder v A pointer is a variable containing an address § Modifying the pointer doesn’t modify what it points to, but you can access/modify what it points to by dereferencing § These work the same in C and C++ int main (int argc, char** argv) { int x = 5 , y = 10 ; int* z = &x; *z += 1 ; // sets x to 6 x += 1 ; // sets x (and *z) to 7 z = &y; // sets z to the address of y *z += 1 ; return EXIT_SUCCESS; }
References v A reference is an alias for another variable § Alias : another name that is bound to the aliased variable
References v A reference is an alias for another variable § Alias : another name that is bound to the aliased variable
References v A reference is an alias for another variable § Alias : another name that is bound to the aliased variable
References v A reference is an alias for another variable § Alias : another name that is bound to the aliased variable
Pass-By-Reference v C++ allows you to truly pass-by- reference § Client passes in an argument with normal syntax
Pass-By-Reference v C++ allows you to truly pass-by- reference § Client passes in an argument with normal syntax
Pass-By-Reference v C++ allows you to truly pass-by- reference § Client passes in an argument with normal syntax
Pass-By-Reference v C++ allows you to truly pass-by- reference § Client passes in an argument with normal syntax