From 4e125cefabc9267057242ee05d6a0363f007b82d Mon Sep 17 00:00:00 2001 From: Jacopo Nespolo Date: Sun, 16 Jul 2023 18:44:34 +0900 Subject: [PATCH 1/2] Update 04-functions.md typo --- 04-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/04-functions.md b/04-functions.md index e6c03b7..a631dc3 100644 --- a/04-functions.md +++ b/04-functions.md @@ -146,7 +146,7 @@ The way the variable `value` is passed from `main()` to `abs_value()` is describ As we have seen, variables which are defined as references are not copies of existing variables, instead they are an alternative name, or *alias*, of a variable **which already exists**. References become particularly useful when defining them in a **different** scope to the variable they reference. As we have seen, a *callee* function cannot access local variables within the *caller* function, instead it can only reference global variables and variables passed as parameters. -Parameter variables an be defined as references by using a single ampersand (`&`) between the type and the variable name in the parameter list. This small and subtle change completely changes the semantics of the function. Changes to a **parameter** variable defined as a *pass by reference* will change the **argument** variable in the calling function, as shown in the following program: +Parameter variables can be defined as references by using a single ampersand (`&`) between the type and the variable name in the parameter list. This small and subtle change completely changes the semantics of the function. Changes to a **parameter** variable defined as a *pass by reference* will change the **argument** variable in the calling function, as shown in the following program: ```cpp // 04-absolute3.cpp : modify a parameter to become its absolute value From 5ec9ffb3bcaac075e0dde6ff4b4fb5d66cd69c2c Mon Sep 17 00:00:00 2001 From: Jacopo Nespolo Date: Sun, 16 Jul 2023 19:14:27 +0900 Subject: [PATCH 2/2] typo --- 03-conditions-and-operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/03-conditions-and-operators.md b/03-conditions-and-operators.md index 3672111..2593170 100644 --- a/03-conditions-and-operators.md +++ b/03-conditions-and-operators.md @@ -4,7 +4,7 @@ The programs we have seen in the previous two chapters have been a little predictable in how they run as they have a *linear execution path* through the `main()` function. Such simple programs have very little practical use. More complex programs, which alter their *control flow* based on *user input* fall into two types. *Batch programs* take all of their input at the beginning of their execution, usually from any or all of: program parameters, an environment variable, or an input file. *Interactive programs* enact a dialog with the *user* (the computer operator) while the program is executing. This dialog is often two-way as the user is not necessarily expected to know what input is required without being prompted. Interactive programs often use either a console or a *GUI* (Graphical User Interface, historically found on desktop computers, but more often found these days on tablets and smartphones). Interactive console programs often produce output to the console *interleaved* with user input, while batch programs ususally know all of their input at the beginning of their execution and produce all of their output following this with no further user involvement or action. As an example of a modern alternative, a purely voice-activated device (possibly without a screen) has an interface which interestingly has more in common with an interactive console program than with a GUI application. -As a compliment to the stream output object `cout`, the stream input object `cin` (an abbreviation of "Character Input") overloads `>>` (the *stream extraction operator*) to allow variables to be set from user input. When a `cin` input expression is reached, the program waits (indefinitely) for the user to type some input and press Enter. The following program outputs a message inviting the user to enter a number, and then prints this number out again on the console. Before `cin` is used, the variable to be used to accept the input into must have already been defined so that the type of the required input can be deduced. Providing an initial value is preferred (empty braces give it a default value) in case the read by `cin` fails due to either invalid input, such as the user typing letters where digits were required, or end-of-input (Ctrl-D or Ctrl-Z): +As a complement to the stream output object `cout`, the stream input object `cin` (an abbreviation of "Character Input") overloads `>>` (the *stream extraction operator*) to allow variables to be set from user input. When a `cin` input expression is reached, the program waits (indefinitely) for the user to type some input and press Enter. The following program outputs a message inviting the user to enter a number, and then prints this number out again on the console. Before `cin` is used, the variable to be used to accept the input into must have already been defined so that the type of the required input can be deduced. Providing an initial value is preferred (empty braces give it a default value) in case the read by `cin` fails due to either invalid input, such as the user typing letters where digits were required, or end-of-input (Ctrl-D or Ctrl-Z): ```cpp // 03-age1.cpp : get and then display an integer