Skip to content

Commit

Permalink
Add content to C++ roadmap
Browse files Browse the repository at this point in the history
  • Loading branch information
kamranahmedse committed Jun 1, 2023
1 parent 36eed57 commit 9f5d1ae
Show file tree
Hide file tree
Showing 92 changed files with 498 additions and 461 deletions.
20 changes: 10 additions & 10 deletions src/data/roadmaps/cpp/content/100-introduction/102-c-vs-cpp.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# C vs C++
C and C++ are two popular programming languages with some similarities, but they also have key differences. C++ is an extension of the C programming language, with added features such as object-oriented programming, classes, and exception handling. Although both languages are used for similar tasks, they have their own syntax and semantics, which makes them distinct from each other.

### Syntax and Semantics
## Syntax and Semantics

#### C
### C
- C is a procedural programming language.
- Focuses on functions and structured programming.
- Does not support objects or classes.
Expand All @@ -22,7 +22,7 @@ int main() {
}
```

#### C++
### C++
- C++ is both procedural and object-oriented.
- Supports both functions and classes.
- Incorporates different programming paradigms.
Expand All @@ -45,27 +45,27 @@ int main() {
}
```
### Code Reusability and Modularity
## Code Reusability and Modularity
#### C
### C
- Code reusability is achieved through functions and modular programming.
- High cohesion and low coupling are achieved via structured design.
- Function libraries can be created and included through headers.
#### C++
### C++
- Offers better code reusability with classes, inheritance, and polymorphism.
- Code modularity is enhanced through namespaces and well-designed object-oriented hierarchy.
### Error Handling
## Error Handling
#### C
### C
- Error handling in C is done primarily through return codes.
- Lacks support for exceptions or any built-in error handling mechanism.
#### C++
### C++
- Offers exception handling, which can be used to handle errors that may occur during program execution.
- Enables catching and handling exceptions with `try`, `catch`, and `throw` keywords, providing more control over error handling.
### Conclusion
## Conclusion
Both C and C++ are powerful languages with unique features and capabilities. While C is simpler and focuses on procedural programming, C++ offers the versatility of using different programming paradigms and improved code organization. Understanding the differences between these two languages can help you decide which one is more suitable for your specific needs and programming style.
20 changes: 10 additions & 10 deletions src/data/roadmaps/cpp/content/100-introduction/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ C++ is a general-purpose, high-performance programming language. It was develope

Here are some basic components and concepts in C++ programming:

### Including Libraries
## Including Libraries

In C++, we use the `#include` directive to include libraries or header files into our program. For example, to include the standard input/output library, we write:

```cpp
#include <iostream>
```

### Main Function
## Main Function

The entry point of a C++ program is the `main` function. Every C++ program must have a `main` function:

Expand All @@ -25,7 +25,7 @@ int main() {
}
```

### Input/Output
## Input/Output

To perform input and output operations in C++, we can use the built-in objects `std::cin` for input and `std::cout` for output, available in the `iostream` library. Here's an example of reading an integer and printing its value:

Expand All @@ -41,7 +41,7 @@ int main() {
}
```

### Variables and Data Types
## Variables and Data Types

C++ has several basic data types for representing integer, floating-point, and character values:

Expand All @@ -59,11 +59,11 @@ double z;
char c;
```

### Control Structures
## Control Structures

C++ provides control structures for conditional execution and iteration, such as `if`, `else`, `while`, `for`, and `switch` statements.

#### If-Else Statement
### If-Else Statement
```cpp
if (condition) {
// Code to execute if the condition is true
Expand All @@ -72,21 +72,21 @@ if (condition) {
}
```

#### While Loop
### While Loop
```cpp
while (condition) {
// Code to execute while the condition is true
}
```

#### For Loop
### For Loop
```cpp
for (initialization; condition; update) {
// Code to execute while the condition is true
}
```

#### Switch Statement
### Switch Statement
```cpp
switch (variable) {
case value1:
Expand All @@ -101,7 +101,7 @@ switch (variable) {
}
```

### Functions
## Functions

Functions are reusable blocks of code that can be called with arguments to perform a specific task. Functions are defined with a return type, a name, a parameter list, and a body.

Expand Down
14 changes: 7 additions & 7 deletions src/data/roadmaps/cpp/content/101-setting-up/100-installing.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Installing C++
Before you can start programming in C++, you will need to have a compiler installed on your system. A compiler is a program that converts the C++ code you write into an executable file that your computer can run. There are several popular C++ compilers to choose from, depending on your operating system and preference.

#### Windows
### Windows
For Windows, one popular option is to install the [Microsoft Visual Studio IDE](https://visualstudio.microsoft.com/vs/), which includes the Microsoft Visual C++ compiler.

Alternatively, you can also install the [MinGW-w64](https://mingw-w64.org/doku.php) compiler, which is a Windows port of the GNU Compiler Collection (GCC). To install MinGW-w64, follow these steps:

1. Download the installer from [here](https://sourceforge.net/projects/mingw-w64/files/).
2. Run the installer and select your desired architecture, version, and install location.
3. Add the `bin` folder inside the installation directory to your system's `PATH` environment variable.
- Download the installer from [here](https://sourceforge.net/projects/mingw-w64/files/).
- Run the installer and select your desired architecture, version, and install location.
- Add the `bin` folder inside the installation directory to your system's `PATH` environment variable.

#### macOS
### macOS
For macOS, you can install the Apple LLVM `clang` compiler which is part of the Xcode Command Line Tools. To do this, open a terminal and enter:

```
Expand All @@ -19,7 +19,7 @@ xcode-select --install

This will prompt a dialog to install the Command Line Tools, which includes the `clang` compiler.

#### Linux
### Linux
On Linux, you can install the GNU Compiler Collection (GCC) through your distribution's package manager. Here are some examples for popular Linux distributions:

- Ubuntu, Debian, and derivatives:
Expand All @@ -37,7 +37,7 @@ sudo dnf install gcc-c++ make
sudo pacman -S gcc make
```

#### Checking the Installation
### Checking the Installation
To confirm that the compiler is installed and available on your system, open a terminal/command prompt, and enter the following command:

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

Code editors are programs specifically designed for editing, managing and writing source code. They offer a wide range of features that make the development process easier and faster. Here's a brief introduction to some of the most popular code editors for C++:

1. **Visual Studio Code (VSCode)**: Visual Studio Code is a popular, free, open-source, and lightweight code editor developed by Microsoft. It has built-in support for C++, along with an extensive library of extensions and plugins.
- **Visual Studio Code (VSCode)**: Visual Studio Code is a popular, free, open-source, and lightweight code editor developed by Microsoft. It has built-in support for C++, along with an extensive library of extensions and plugins.

2. **Sublime Text**: Sublime Text is a cross-platform text editor that is quite popular among developers due to its speed and minimalist design. It supports C++ with the help of plugins and has a variety of themes and packages available for customization.
- **Sublime Text**: Sublime Text is a cross-platform text editor that is quite popular among developers due to its speed and minimalist design. It supports C++ with the help of plugins and has a variety of themes and packages available for customization.

3. **CLion**: CLion is an Integrated Development Environment (IDE) developed by JetBrains specifically for C and C++ developers. It provides advanced features like code completion, refactoring support, debugging, and more.
- **CLion**: CLion is an Integrated Development Environment (IDE) developed by JetBrains specifically for C and C++ developers. It provides advanced features like code completion, refactoring support, debugging, and more.

These are just a few examples, and there are many other code editors available, including Atom, Notepad++, and Geany. They all have their features and may suit different developers' needs. Finding the right code editor is often a matter of personal preference and workflow.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ int main() {

Let's break down the different components of this program:

### Header Files & Preprocessor Directives
## Header Files & Preprocessor Directives

The first line of the program `#include <iostream>` is a [preprocessor directive](https://en.cppreference.com/w/cpp/preprocessor) that tells the compiler to include the header file `iostream`. Header files provide function and class declarations that we can use in our C++ programs.

```cpp
#include <iostream>
```

### `main()` Function
##`main()` Function

In C++, the `main()` function serves as the entry point of your program. The operating system runs your program by calling this `main()` function. It should be defined only once in your program and must return an integer.

Expand All @@ -35,7 +35,7 @@ int main() {
}
```

### Output to the Console
## Output to the Console

To output text to the console, we use the `std::cout` object and the insertion operator `<<`. In the "Hello, World!" example, we used the following line to print "Hello, World!" to the console:

Expand All @@ -47,7 +47,7 @@ std::cout << "Hello, World!" << std::endl;
- `"Hello, World!"`: The string literal to print
- `std::endl`: The "end line" manipulator that inserts a newline character and flushes the output buffer

### Return Statement
## Return Statement

Lastly, the `return 0;` statement informs the operating system that the program executed successfully. Returning any other integer value indicates that an error occurred:

Expand Down
14 changes: 7 additions & 7 deletions src/data/roadmaps/cpp/content/101-setting-up/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ After downloading and installing an IDE, you might need to configure it to use t

Once you have your IDE and compiler set up, you can create a new C++ project and start writing code. In general, follow these steps to create a new C++ project:

1. Open the IDE and create a new project.
2. Select the project type (C++ Application or Console Application).
3. Specify the project name and location.
4. Let the IDE generate the main.cpp and build files (such as Makefile or CMakeLists.txt) for you.
- Open the IDE and create a new project.
- Select the project type (C++ Application or Console Application).
- Specify the project name and location.
- Let the IDE generate the main.cpp and build files (such as Makefile or CMakeLists.txt) for you.

## Example: Hello World in C++

Expand All @@ -50,8 +50,8 @@ Then, follow the IDE's instructions to build and run your program. You should se

Setting up C++ involves:

1. Installing a compiler (e.g. GCC, MinGW, or MSVC)
2. Configuring an IDE (e.g. Visual Studio, Eclipse, or Code::Blocks)
3. Creating a new C++ project and writing code
- Installing a compiler (e.g. GCC, MinGW, or MSVC)
- Configuring an IDE (e.g. Visual Studio, Eclipse, or Code::Blocks)
- Creating a new C++ project and writing code

By following these steps, you'll be ready to start developing C++ applications!
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Logical operators are used to perform logical operations on the given expression

C++ provides the following logical operators:

1. **AND Operator (&&)**
- **AND Operator (&&)**
The AND operator checks if both the operands/conditions are true, then the expression is true. If any one of the conditions is false, the whole expression will be false.
```
(expression1 && expression2)
Expand All @@ -16,7 +16,7 @@ C++ provides the following logical operators:
cout << "Both values are positive." << endl;
}
```
2. **OR Operator (||)**
- **OR Operator (||)**
The OR operator checks if either of the operands/conditions are true, then the expression is true. If both the conditions are false, it will be false.
```
(expression1 || expression2)
Expand All @@ -29,7 +29,7 @@ C++ provides the following logical operators:
}
```

3. **NOT Operator (!)**
- **NOT Operator (!)**
The NOT operator reverses the result of the condition/expression it is applied on. If the condition is true, the NOT operator will make it false and vice versa.
```
!(expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bitwise operations are operations that directly manipulate the bits of a number.

Here is a quick summary of common bitwise operations in C++:

### 1. Bitwise AND (`&`)
## Bitwise AND (`&`)

The bitwise AND operation (`&`) is a binary operation that takes two numbers, compares them bit by bit, and returns a new number where each bit is set (1) if the corresponding bits in both input numbers are set (1); otherwise, the bit is unset (0).

Expand All @@ -14,7 +14,7 @@ Example:
int result = 5 & 3; // result will be 1 (0000 0101 & 0000 0011 = 0000 0001)
```

### 2. Bitwise OR (`|`)
## Bitwise OR (`|`)

The bitwise OR operation (`|`) is a binary operation that takes two numbers, compares them bit by bit, and returns a new number where each bit is set (1) if at least one of the corresponding bits in either input number is set (1); otherwise, the bit is unset (0).

Expand All @@ -24,7 +24,7 @@ Example:
int result = 5 | 3; // result will be 7 (0000 0101 | 0000 0011 = 0000 0111)
```

### 3. Bitwise XOR (`^`)
## Bitwise XOR (`^`)

The bitwise XOR (exclusive OR) operation (`^`) is a binary operation that takes two numbers, compares them bit by bit, and returns a new number where each bit is set (1) if the corresponding bits in the input numbers are different; otherwise, the bit is unset (0).

Expand All @@ -34,7 +34,7 @@ Example:
int result = 5 ^ 3; // result will be 6 (0000 0101 ^ 0000 0011 = 0000 0110)
```

### 4. Bitwise NOT (`~`)
## Bitwise NOT (`~`)

The bitwise NOT operation (`~`) is a unary operation that takes a single number, and returns a new number where each bit is inverted (1 becomes 0, and 0 becomes 1).

Expand All @@ -44,7 +44,7 @@ Example:
int result = ~5; // result will be -6 (1111 1010)
```

### 5. Bitwise Left Shift (`<<`)
## Bitwise Left Shift (`<<`)

The bitwise left shift operation (`<<`) is a binary operation that takes two numbers, a value and a shift amount, and returns a new number by shifting the bits of the value to the left by the specified shift amount. The vacated bits are filled with zeros.

Expand All @@ -54,7 +54,7 @@ Example:
int result = 5 << 1; // result will be 10 (0000 0101 << 1 = 0000 1010)
```

### 6. Bitwise Right Shift (`>>`)
## Bitwise Right Shift (`>>`)

The bitwise right shift operation (`>>`) is a binary operation that takes two numbers, a value and a shift amount, and returns a new number by shifting the bits of the value to the right by the specified shift amount. The vacated bits are filled with zeros or sign bit depending on the input value being signed or unsigned.

Expand Down
Loading

0 comments on commit 9f5d1ae

Please sign in to comment.