tailieunhanh - Absolute C++ (4th Edition) part 12

Absolute C++ (4th Edition) part 12. KEY BENEFIT: C++ programming concepts and techniques are presented in a straightforward style using understandable language and code. KEY TOPICS: C++ Basics; Flow of Control; Function Basics; Parameters and Overloading; Arrays; Structures and Classes; Constructors; Operator Overloading, Friends, and References; Strings; Pointers and Dynamic Arrays; Separate Compilation and Namespaces; Streams and File I/O; Recursion; Inheritance; Polymorphism and Virtual Functions; Templates; Linked Data Structures; Exception Handling; Standard Template Library; Patterns and UML. MARKET: Useful for both beginning and intermediate C++ programmers. . | 112 Function Basics functions with no arguments void functions and return statements Notice that the function call ends with a semicolon which tells the compiler that the function call is an executable statement. When a void function is called the arguments are substituted for the formal parameters and the statements in the function body are executed. For example a call to the void function showResults which we gave earlier in this section will cause some output to be written to the screen. One way to think of a call to a void function is to imagine that the body of the function definition is copied into the program in place of the function call. When the function is called the arguments are substituted for the formal parameters and then it is just as if the body of the function were lines in the program. Chapter 4 describes the process of substituting arguments for formal parameters in detail. Until then we will use only simple examples that should be clear enough without a formal description of the substitution process. It is perfectly legal and sometimes useful to have a function with no arguments. In that case there simply are no formal parameters listed in the function declaration and no arguments are used when the function is called. For example the void function initializeScreen defined below simply sends a newline command to the screen void initializeScreen cout endl If your program includes the following call to this function as its first executable statement then the output from the previously run program will be separated from the output for your program initializeScreen Be sure to notice that even when there are no parameters to a function you still must include the parentheses in the function declaration and in a call to the function. Placement of the function declaration function prototype and the function definition is the same for void functions as what we described for functions that return a value. return STATEMENTS IN void FUNCTIONS Both void .

TỪ KHÓA LIÊN QUAN