20-11-2012, 12:13 PM
Program Components in C++
Components in C++.ppt (Size: 330.5 KB / Downloads: 22)
Introduction
Divide and conquer
Construct a program from smaller pieces or components
Each piece more manageable than the original program
Program Components in C++
Modules: functions and classes
Programs use new and “prepackaged” modules
New: programmer-defined functions, classes
Prepackaged: from the standard library
Functions invoked by function call
Function name and information (arguments) it needs
Function definitions
Only written once
Hidden from other functions
Functions
Functions
Modularize a program
Software reusability
Call function multiple times
Local variables
Known only in the function in which they are defined
All variables declared in function definitions are local variables
Parameters
Local variables passed to function when called
Provide outside information
Storage Classes
Automatic storage class
Variable created when program enters its block
Variable destroyed when program leaves block
Only local variables of functions can be automatic
Automatic by default
keyword auto explicitly declares automatic
register keyword
Hint to place variable in high-speed register
Good for often-used items (loop counters)
Often unnecessary, compiler optimizes
Specify either register or auto, not both
register int counter = 1;