Skip to content

Commit

Permalink
fixed errors in io, eqordlogic & condexpr
Browse files Browse the repository at this point in the history
minor errors i picked up while reading through the content.
  • Loading branch information
osmanhaji committed Apr 9, 2023
1 parent becba81 commit deac97b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/chapter2/condexpr.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Conditional expressions use the concepts of equality and ordering to allow progr

## Scope

One important concept in programming is the idea of scope. In C++, scope is very important as it can have an important impact on the design, performance in the safety of a program. Currently we have been running a program purely in the scope of the `main()` function. What denotes a scope in C++ is a pair of braces `{}`. Anything introduced within the braces is now in a new scope separate from the outside program. Objects from outside the new scope can be captured but anything created in a new scope is dropped at the end of the scope.
One important concept in programming is the idea of scope. In C++, scope is very important as it can have an important impact on the design, performance and the safety of a program. Currently we have been running a program purely in the scope of the `main()` function. What denotes a scope in C++ is a pair of braces `{}`. Anything introduced within the braces is now in a new scope separate from the outside program. Objects from outside the new scope can be captured but anything created in a new scope is dropped at the end of the scope.

```cxx
#include <iostream>
Expand Down Expand Up @@ -63,7 +63,7 @@ auto main () -> int

[Example](https://www.godbolt.org/z/4dK3P17ax)

We can also use an `else` clause at the end. This indicates that if and `if` expression fails, the `else` clause will execute instead.
We can also use an `else` clause at the end. This indicates that if an `if` expression fails, the `else` clause will execute instead.

```cxx
#include <iostream>
Expand Down
6 changes: 3 additions & 3 deletions src/chapter2/eqordlogic.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ auto main () -> int

## Ordering

Checking for equality is pretty straight forward. Some more interesting operations are the ordering operators. What is ordering? Ordering is a relationship of different values of the same type. Ordering is what gives numbers their sequence (`2 < 3`). Ordering operators allow use to check if some ordering condition is met.
Checking for equality is pretty straight forward. Some more interesting operations are the ordering operators. What is ordering? Ordering is a relationship of different values of the same type. Ordering is what gives numbers their sequence (`2 < 3`). Ordering operators allow us to check if some ordering condition is met.

- `<` - Less than
- `>` - Greater than
Expand Down Expand Up @@ -69,7 +69,7 @@ auto main () -> int

## Spaceships and Ordering Types

As of C++20 there as a new ordering operator introduced called the three-way-comparison operator or, the spaceship operator `<=>`. The spaceship operator different ordering types based on the strictness of the ordering.
As of C++20 there is a new ordering operator introduced called the three-way-comparison operator or, the spaceship operator `<=>`. The spaceship operator has different ordering types based on the strictness of the ordering.

- `(a <=> b) < 0` if `a < b`
- `(a <=> b) > 0` if `a > b`
Expand Down Expand Up @@ -155,7 +155,7 @@ In programming, it is useful to be able to check a multitude of Boolean expressi
- `&&` - Logical And
- `||` = Logical Or

Logical And and Or have special short circuiting properties. This means that the outcome of a Boolean expressions can be evaluated early. For And, if one Boolean point is `false`, it doesn't matter what the second point evaluates to as the expression's condition has already failed, thus whole expression would `false`. Inversely for Or, if one Boolean point is `true` the whole expression is true
Logical And and Or have special short circuiting properties. This means that the outcome of a Boolean expressions can be evaluated early. For And, if one Boolean point is `false`, it doesn't matter what the second point evaluates to as the expression's condition has already failed, thus the whole expression is `false`. Inversely for Or, if one Boolean point is `true` the whole expression is true

> Note: There is no logical Xor. This is because Xor cannot short circuited as the result depends on the result of both points. However, we have already seen the logical Xor, it is the `!=`. If the two points of `!=` are either both `true` or both `false`, the inequality condition is not met and thus achieving the exclusivity properties of Xor. In C++ because `bool` can be implicitly converted to other integral types, it is best that logicalXor is used as: `!(a) != !(b)`.
Expand Down
4 changes: 2 additions & 2 deletions src/chapter2/io.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ IO means input and output. IO operations are used to consume or emit data at the

## What is a stream?

What is a stream. A stream is a sequence of an indeterminate amount of data connecting a source to a destination. In C++, streams are used to connect a perform a variety of IO operations. You have already used on of these streams in C++, this is of course `std::cout`.
What is a stream. A stream is a sequence of an indeterminate amount of data connecting a source to a destination. In C++, streams are used to connect and perform a variety of IO operations. You have already used on of these streams in C++, this is of course `std::cout`.

## C Standard Streams

In C++ there are a few pre-defined stream objects. This are mounted to the the C languages `stdout`, `stdin` and `stderr`. These output devices are how C (and these stream objects) connect to the terminal screen and keyboard of your device.
In C++ there are a few pre-defined stream objects. These are mounted to the C languages `stdout`, `stdin` and `stderr`. These output devices are how C (and these stream objects) connect to the terminal screen and keyboard of your device.

- `std::cin` - Output stream to C's `stdin`
- `std::cout` - Output stream to C's `stdout`
Expand Down

0 comments on commit deac97b

Please sign in to comment.