C++ Review
C++ Review
Outline ■C++ basic features Programming paradigm and statement syntax ■C| ass definitions Data members methods constructor destructor Pointers, arrays, and strings Parameter passing in functions Templates Friend Operator overloading O streams An example on file copy Makefile
2 Outline ◼ C++ basic features ◼ Programming paradigm and statement syntax ◼ Class definitions ◼ Data members, methods, constructor, destructor ◼ Pointers, arrays, and strings ◼ Parameter passing in functions ◼ Templates ◼ Friend ◼ Operator overloading ◼ I/O streams ◼ An example on file copy ◼ Makefile
Functions memory Every function needs a place to store its local variables Memory Collectively this storage is called location the stack This storage(memory aka "RAM) d2 Is a series of storage spaces and their numerical addresses Instead of using raw addresses we use variables to attach a name to an address all of the data/variables for a particular function call are located void aFunc(int x, int y) in a stack frame double d1, d2; int 1
3 Functions & Memory ◼ Every function needs a place to store its local variables. Collectively, this storage is called the stack ◼ This storage (memory aka “RAM”), is a series of storage spaces and their numerical addresses ◼ Instead of using raw addresses, we use variables to attach a name to an address ◼ All of the data/variables for a particular function call are located in a stack frame Memory location void aFunc(int x, int y) { double d1, d2; int i; } x y d2 d1 i
Functions memory(cont) When a function is called a new stack frame is set aside Parameters and return values are passed by copy(ie, they' re copied into and out of the stack frame) When a function finishes its stack frame is reclaimed void afunc (int x, int y) double dl=x+ int main(int argc, const char argv[])[ int x =7 a Func(1, 2) Y aFunc a Func(2,3)i return 0; 7 main
4 Functions & Memory (cont) ◼ When a function is called, a new stack frame is set aside ◼ Parameters and return values are passed by copy (ie, they’re copied into and out of the stack frame) ◼ When a function finishes, its stack frame is reclaimed void aFunc(int x, int y) { double d1 = x + y; } int main(int argc, const char * argv[]) { int x = 7; aFunc(1, 2); aFunc(2, 3); return 0; } x y d1 x 7 aFunc main
Programming Paradigm: Modular Concept program maln program dat module 1 module data +date data +da 2 DLCCCauLc procedure procedure The main program coordinates calls to procedures in separate modules and hands over appropriate data as parameters
5 Programming Paradigm: Modular Concept ◼ The main program coordinates calls to procedures in separate modules and hands over appropriate data as parameters