DOC PREVIEW
WUSTL CSE 332S - midterm_review

This preview shows page 1-2-17-18-19-36-37 out of 37 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSE 332 Midterm ReviewWhat Goes Into a C++ Program?Lifecycle of a C++ ProgramWhat’s a Pointer?What’s a Reference?Const Pointers and Pointers to ConstRules for Pointer ArithmeticExpressions: Operators and OperandsC++ StatementsC++ Exceptions Interrupt Control FlowDetails About Catching Exceptions in C++More About Catching Exceptions in C++How Function Calls WorkPass By ValuePass By ReferenceStructure of a Simple C++ Class DeclarationConstructorsAccess ControlFriend DeclarationsFriends ExampleFlushing Streams (and Stream Manipulators)A Few More Details About StreamsContainers’ IteratorsProperties of Iterator IntervalsThe vector ContainerThe list ContainerLinear Search with Generic IteratorsKey Ideas: Concepts and ModelsConcepts and Models, ContinuedMatching an Algorithm to the Iterators it NeedsIterator Concept HierarchyCan Extend STL Algorithms with Callable ObjectsAssociative ContainersKey Types, Comparators, Strict Weak OrderingAssociative Containers’ Associated TypesAssociative Containers’ Operators and MethodsCSE 332 Midterm (During Class Time)CSE 332: Midterm ReviewCSE 332 Midterm Review•Goals for today’s review–Review and summary of material in course so far•A chance to clarify and review key concepts/examples–Discuss details about the midterm exam•Whitaker 218, Tue Mar. 8 during class•Notes on only 1 side of an 8.5”x11” page will be allowed•All electronics must be off, including cell phones, etc. •Recommendations for exam preparation–Catch up on any studios/readings you’ve not done–Write up your notes page as you study–Ask questions here as you have them todayCSE 332: Midterm ReviewWhat Goes Into a C++ Program?•Declarations: data types, function signatures, classes–Allows the compiler to check for type safety, correct syntax–Usually kept in “header” (.h) files–Included as needed by other files (to keep compiler happy)class Simple { typedef unsigned int UINT32; public: Simple (int i); int usage (char * program_name); void print_i (); private: struct Point2D { int i_; double x_;}; double y_; };•Definitions: static variable initialization, function implementation–The part that turns into an executable program –Usually kept in “source” (.cpp) filesvoid Simple::print_i () {cout << “i_ is ” << i_ << endl;} •Directives: tell compiler (or precompiler) to do something–More on this laterCSE 332: Midterm ReviewLifecycle of a C++ ProgramC++ source codeMakefileProgrammer(you)object code (binary, one per compilation unit) .omake“make” utilityxtermconsole/terminal/windowRuntime/utility libraries(binary) .lib .a .dll .sogcc, etc.compilerlinklinkerE-mailexecutableprogramEclipsedebuggerprecompilercompilerlinkturnin/checkinAn “IDE”WebCATVisual StudiowindowcompileCSE 332: Midterm ReviewWhat’s a Pointer?•A variable holding an address–Of what it “points to” in memory•Can be untyped–E.g., void * v; // points to anything•However, usually they’re typed –Checked by compiler–Can only be assigned addresses of variables of type to which it can point–E.g., int * p; // only points to int•Can point to nothing– E.g., p = 0; // or p = nullptr; (C++11)•Can change where it points–As long as pointer itself isn’t const –E.g., p = &i; // now points to i0x7fffdad07int iint *pCSE 332: Midterm ReviewWhat’s a Reference?•Also a variable holding an address–Of what it “refers to” in memory•But with a nicer interface–A more direct alias for the object–Hides indirection from programmers•Must be typed –Checked by compiler–Again can only refer to the type with which it was declared–E.g., int & r =i; // refers to int i•Always refers to (same) something–Must initialize to refer to a variable–Can’t change what it aliases 0x7fffdad07int iint & rCSE 332: Midterm ReviewConst Pointers and Pointers to Constint main (int argc, char **argv){ const int i = 0; int j = 1; int k = 2; // pointer to int int * w = & j; // (array names are like const // pointers to their 0th position) // const pointer to int int * const x = & j; // pointer to const int const int * y = & i; // const pointer to const int const int * const z = & j;} •Read declarations right to left•Make promises via the const keyword in pointer declaration:–not to change where the pointer points– not to change value at the location to which it points•Can (only) change–Where w points and the value at the location to which it points–The value at the location to which x points–Where y points•A pointer to non-const cannot point to a const variable–neither w nor x can point to i–any of them can point to jCSE 332: Midterm ReviewRules for Pointer Arithmeticint main (int argc, char **argv){ int arr [3] = {0, 1, 2}; int * p = & arr[0]; int * q = p + 1; return 0;} •You can subtract (but not add, multiply, etc.) pointers–Gives an integer with the distance between them•You can add/subtract an integer to/from a pointer–E.g., p+(q-p)/2 is allowed but (p+q)/2 gives an error •Note relationship between array and pointer arithmetic –Given pointer p and integer n, the expressions p[n] and *(p+n) are both allowed and mean the same thing0xefffdad02int arr [3]int *p10xefffdad0int *q0CSE 332: Midterm ReviewExpressions: Operators and Operands•Operators obey arity, associativity, and precedenceint result = 2 * 3 + 5; // assigns 11•Operators are often overloaded for different typesstring name = first + last; // concatenation•An lvalue gives a location; an rvalue gives a value–Left hand side of an assignment must be an lvalue–Prefix increment and decrement take and produce lvalues–Posfix versions (and &) take lvalues, produce rvalues•Beware accidentally using the “future equivalence” operator, e.g., if (i = j) instead of if (i == j)•Avoid type conversions if you can, and only use named casts (if you must explicitly convert types)CSE 332: Midterm ReviewC++ Statements•In C++ statements are basic units of execution–Each ends with ; (can use expressions to compute values)–Statements introduce scopes, e.g., of (temporary) variables•A (useful) statement usually has a side effect –Stores a value for future use: j = i + 5;–Performs input or


View Full Document

WUSTL CSE 332S - midterm_review

Download midterm_review
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view midterm_review and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view midterm_review 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?