Skip to content

Corrected some typos #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions week01/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ int mul(int a, int b)
return n1 * n2
}
```
The compilation error messages generated by the prevous source code.
The compilation error messages generated by the previous source code.
```console
$ g++ -c mul.cpp
mul.cpp:5:12: error: use of undeclared identifier 'n1'
Expand All @@ -206,7 +206,7 @@ mul.cpp:5:19: error: expected ';' after return statement
3 errors generated.
```

If there are compilation errors, it is better to check the source code to make sure all spells are correct, no `;` or `(` missing. For peole in East Asia, they should also be very careful with characters like `;`, `)`, etc. They are different from `;` and `)`. Another Chinese character ` ` which is a wider space is easy to be miss used with the normal space.
If there are compilation errors, it is better to check the source code to make sure all spells are correct, no `;` or `(` missing. For people in East Asia, they should also be very careful with characters like `;`, `)`, etc. They are different from `;` and `)`. Another Chinese character ` ` which is a wider space is easy to be miss used with the normal space.

### Link Errors

Expand All @@ -215,12 +215,12 @@ Link errors are caused in the link stage. The most common link error is `undefin
//mul.cpp
#include "mul.hpp"

int Mul(int a, int b) //mul() is callled in main() but here it is Mul()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here function name should be 'mul' as in the main it is mentioned it is mul()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and this is the example showing link error due to a function name typo. I just fixed the typo "callled" to "called".

int Mul(int a, int b) //mul() is called in main() but here it is Mul()
{
return a * b;
}
```
You will get a link error as follows even you can comile the two files `main.cpp` and `mul.cpp` separately.
You will get a link error as follows even you can compile the two files `main.cpp` and `mul.cpp` separately.
```console
$ g++ main.o mul.o -o mul
Undefined symbols for architecture arm64:
Expand Down Expand Up @@ -279,7 +279,7 @@ double len(double r)
}
```

Since macros behaviors like text replacement, sometimes it is dangerous and cause bugs. If we define `PI` as `2.14+1.0`, the statement is grammatically correct.
Since macros behaves like text replacement, sometimes it is dangerous and cause bugs. If we define `PI` as `2.14+1.0`, the statement is grammatically correct.

```cpp
#define PI 2.14+1.0
Expand All @@ -289,7 +289,7 @@ double len(double r)
}
```

But after preprocessing the return value of the function will be `4.28+r`, not `2.0*3.14*r`. It may be not what you expected. Anyway, the source code will be compiled successfully, and the compiler will not report any warning or error. You should be very careful when you use macros.
But after preprocessing the return value of the function will be `4.28+r`, not `2.0*3.14*r`. It may not be what you expected. Anyway, the source code will be compiled successfully, and the compiler will not report any warning or error. You should be very careful when you use macros.

```cpp
double len(double r)
Expand Down
9 changes: 5 additions & 4 deletions week02/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This line is to declare and initialize a variable.
int n = 10; //declare and initialize
```

The following line looks very similar to the previous one. But the operations are different. But no initialization is in it. The first line is declaring a variable, and the second is assigning a value. Assignment is a different operation from initialization. The two pieces of source code are equivalent. They both declare a variable, and then its value is `10`. But if the data type is not a fundamental type (`int`, `float`, etc) and is a compound type (such as a `class` type), the two operations, initialization and assignment, may have different behaviors. The reason is that the operations in an initialization function may be different from those in an assignment function. You can get related information in the operator overloading part of this book.
The following line looks very similar to the previous one. But the operations are different. No initialization is in it. The first line is declaring a variable, and the second is assigning a value. Assignment is a different operation from initialization. The two pieces of source code are equivalent. They both declare a variable, and then its value is `10`. But if the data type is not a fundamental type (`int`, `float`, etc) and is a compound type (such as a `class` type), the two operations, initialization and assignment, may have different behaviors. The reason is that the operations in an initialization function may be different from those in an assignment function. You can get related information in the operator overloading part of this book.

```cpp
int n; //declare a variable, its value may be a random one
Expand Down Expand Up @@ -139,7 +139,7 @@ The data widths of different integers are listed in the following table. For mor

### Signed and Unsigned Integers

`signed` or `unsigned` can be used before the integer type names to indicate if the integer is a signed one or unsigned one. When the integer is a signed one, the keyword `signed` can be omitted. It means `int` is for `signed int`, and `short` is for `signed short`. But there is an exception. `char` is not always for `signed char`, and it is `unsigned char` on some platforms. I strongly suggest always using `signed char`` or `unsigned char`, and not using `char`.
`signed` or `unsigned` can be used before the integer type names to indicate if the integer is a signed one or unsigned one. When the integer is a signed one, the keyword `signed` can be omitted. It means `int` is for `signed int`, and `short` is for `signed short`. But there is an exception. `char` is not always for `signed char`, and it is `unsigned char` on some platforms. I strongly suggest always using `signed char` or `unsigned char`, and not using `char`.

If the integer is a signed one, the highest bit (the 32nd bit for `int`) will be its sign bit. It is a negative number if the sign bit is 1, and a positive number if it is 0. The signed int and unsigned int are shown in the following figure.

Expand Down Expand Up @@ -259,6 +259,7 @@ Before introducing floating-point numbers, I would like to introduce the followi

```cpp
//float.cpp
#include <iostream>
#include <iomanip>
using namespace std;
int main()
Expand Down Expand Up @@ -410,7 +411,7 @@ The arithmetric operators are listed in the following table.
| bitwise left shift | `a << b` |
| bitwise right shift | `a >> b` |

The operators and their operants can be connected together to create an expression. Some are simple ones such as `a + b`, and some may be long ones with multiple operators such as `a + b * c / (e + f)`. The expression can be assigned to a variable.
The operators and their operands can be connected together to create an expression. Some are simple ones such as `a + b`, and some may be long ones with multiple operators such as `a + b * c / (e + f)`. The expression can be assigned to a variable.

```cpp
int result = a + b * c / (e + f);
Expand Down Expand Up @@ -454,7 +455,7 @@ The following code may also be easy to mislead us. Since `17` and `5` are all `i
float float_num = 17 / 5; // f = 3.0f, not 3.4f.
```

When we convert numbers according to the direction from `char` -> `short` -> `int` -> `long` -> `float` -> `double` -> `long double`, normally there is not data loss. But if the conversion is in the opposite direction from `long double` to `char`, it will cause data loss and compilers will warn you most of the time. But it is not always true. Some big integer numbers in `int` may loss precision when they are converted to `float` as shown in the following code.
When we convert numbers according to the direction from `char` -> `short` -> `int` -> `long` -> `float` -> `double` -> `long double`, normally there is not data loss. But if the conversion is in the opposite direction from `long double` to `char`, it will cause data loss and compilers will warn you most of the time. But it is not always true. Some big integer numbers in `int` may lose precision when they are converted to `float` as shown in the following code.

```cpp
int num_int1 = 100000004;
Expand Down