# Section 5: C++ Basics

## Compound Assignment

1. +=, -=, *=, /=, %=.
2. &=, |=, <<=, >>=.
3. example

## Increment and Decrement Operators

1. pre increment ++x;
2. post increment x++;
3. pre decrement --x;
4. post decrement x–;
5. Pre increment add value to variable first, then execute the others. Post increment execute the assignment, then add value to variable.
• pre increment.
• post increment
6. Complicated example.

## Overflow

1. Overflow is if a value is more than the capacity, it will take the values from the beginning. For example, char x = 127;, x++;, then the x will become -128.

## Bitwise Operators

1. & and.
2. | or.
3. ^ X-OR.
4. ~ not.
5. << shift left.
6. >> shift right.
7. Example.
8. Shift example. If x shift i left x << i, the result is $x*2^i$. On the contrary, if x shift i right x >> i, the result is $\frac{x}{2^i}$.

## Enum and Typedef

1. If you have a set of words, you want to use them efficiently. You can use enum to make these words as the constant numbers. You can even assign the number to the constant. If you don’t assign the number, enum will add one from the previous one to the current word. Here is the example.
2. typedef is used for making variable readable. You can define the variables by yourself. For example, you can know m1 means marks and it is int type.

# Section 6

## Conditional Statement - if

1. Relational Operators
• <
• <=
• >
• >=
• ==
• !=

1. Example.

1. && AND
2. || OR
3. ! NOT

## Nested if

1. Example: Find the max of 3 numbers.

1. Example

## short circuit

1. If the logical operator is AND in the statement and the first one is false, the second condition will not be executed since the result will always be false. If the logical operator is OR in the statement and the first one is true, the second condition will not be executed since the result will always be true.

## Dynamic Declaration

1. The variables inside the if block will be removed from the memory after the statement is executed. After the C++ 17, you can declare the variable in the IF statement if you don’t want to use it after you ran the if code block.
2. For loop is as same as the IF statement.
3. You can put the variable inside another code block, then the variable can’t be read outside the code block.

## Switch Case - Branch and Control

1. Example. Using Switch is faster than if else ladder, it jumps to the case directly.

# Disclaimer

I took this course from Udemy, which is Learn C++ Programming -Beginner to Advance- Deep Dive in C++. I only took some notes of this amazing course for my personal future uses and share my thoughts with my peers. If you like it, you should take the course from Udemy too.

Share