|
|
|
|
|
|
|
Back in main().
c was set to 8
Exiting |
|
|
|
|
|
|
|
|
Analysis: The function Add() is defined on line 2. It takes two integer parameters and returns an integer value. The program itself begins on line 11 where it prints a message. The program prompts the user for two numbers (lines 13 to 15). The user types each number, separated by a space, and then presses Enter. Main() passes the two numbers typed in by the user as arguments to the Add() function on line 17. |
|
|
|
|
|
|
|
|
Processing branches to the Add() function, which starts on line 2. The parameters a and b are printed and then added together. The result is returned on line 6 and the function returns. |
|
|
|
|
|
|
|
|
In lines 14 and 15, the cin object is used to obtain a number for the variables a and b, and cout is used to write the values to the screen. Variables and other aspects of this program will be explored in depth in the next few days. |
|
|
|
|
|
|
|
|
In this hour you examined a program in some detail. You learned how to include files using #include, and you learned how to use comments well. You also learned what a function is and how it is used in a program. |
|
|
|
|
|
|
|
|
A This is a directive to the preprocessor, which runs when you call your compiler. This specific directive causes the file named after the word include to be read in as if it were typed in at that location in your source code. |
|
|
|
|
|
|
|
|
Q What is the difference between // comments and /* style comments? |
|
|
|
|
|
|
|
|
A The double-slash comments (//) expire at the end of the line. Slash-star (/*) comments are in effect until a closing comment (*/). Remember, not even the end of the function terminates a slash-star comment; you must put in the closing comment mark or you will get a compile-time error. |
|
|
|
|
|
|
|
|
Q What differentiates a good comment from a bad comment? |
|
|
|
|
|
|
|
|
A A good comment tells the reader why this particular code is doing whatever it is doing, or explains what a section of code is about to do. A bad comment restates what a particular line of code is doing. Lines of code should be written so that they speak for themselves: reading the line of code should tell you what it is doing without needing a comment. |
|
|
|
|
|