Skip to content

Cpp docs added #560

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

Merged
merged 6 commits into from
Jun 6, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,71 @@ tags:
c++ data types
]
description: In this tutorial, we will learn about variables and data types in C++. We will learn about what variables are, how to declare and initialize variables, and the different data types available in the language.
---
---

# Variables and Data Types in C++

## Data Types

C++ is a strongly-typed language, meaning every variable must be declared with a data type.

### Primitive Data Types

- **int**: Integer type.
- **double**: Double-precision floating point.
- **char**: Character type.
- **bool**: Boolean type (true or false).

Example:

```cpp
int number = 10;
double price = 9.99;
char letter = 'A';
bool isCppFun = true;
```

### Derived Data Types

Derived data types are created from fundamental data types.

- **Array**: A collection of elements of the same data type.
- **Pointer**: A variable that stores the memory address of another variable.
- **Reference**: A reference to another variable, often used in functions.

Example:

```cpp
int numbers[] = {1, 2, 3, 4, 5};
int* ptr = &number;
int& refNumber = number;
```

## Variables

Variables store data values and must be declared before use.

### Variable Declaration

```cpp
int age;
char grade;
```

### Variable Initialization

```cpp
age = 25;
grade = 'A';
```

### Combined Declaration and Initialization

```cpp
int age = 25;
char grade = 'A';
```

## Conclusion

Understanding C++ variables and data types is fundamental to writing efficient and effective C++ code. By mastering these concepts, you can work with different types of data and create dynamic and robust applications in C++.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,71 @@ sidebar_position: 3
tags:
[c++, operators, expressions, programming, c++ operators, c++ expressions]
description: In this tutorial, we will learn about operators and expressions in C++. We will learn about the different types of operators available in C++, how to use them, and how to create expressions using operators.
---
---

# Operators and Expressions in C++

## Operators

C++ supports various operators for arithmetic, comparison, logical operations, etc.

### Arithmetic Operators

- `+` (addition)
- `-` (subtraction)
- `*` (multiplication)
- `/` (division)
- `%` (modulus)

Example:

```cpp
int sum = 10 + 5; // 15
int difference = 10 - 5; // 5
```

### Comparison Operators

- `==` (equal to)
- `!=` (not equal to)
- `>` (greater than)
- `<` (less than)
- `>=` (greater than or equal to)
- `<=` (less than or equal to)

Example:

```cpp
bool isEqual = (10 == 10); // true
bool isGreater = (10 > 5); // true
```

### Logical Operators

- `&&` (logical AND)
- `||` (logical OR)
- `!` (logical NOT)

Example:

```cpp
bool result = (true && false); // false
bool orResult = (true || false); // true
```

## Expressions

Expressions in C++ are formed using operators and operands. An expression can be a combination of literals, variables, and operators.

Example:

```cpp
int x = 10;
int y = 5;
int z = x + y; // z = 15
bool isTrue = (x > y) && (z != y); // true
```

## Conclusion

Understanding C++ operators and expressions is fundamental to writing effective C++ code. By mastering these concepts, you can perform various operations and create complex expressions in your C++ programs.
87 changes: 86 additions & 1 deletion docs/cpp/basic-syntax-and-structure/cpp-syntax-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,89 @@ tags:
c++ features,
]
description: In this tutorial, we will learn about the syntax and structure of the C++ programming language. We will learn about the basic structure of a C++ program, C++ syntax, and the rules that govern the C++ programming language.
---
---

# C++ Syntax and Structure

## Introduction

Understanding the basic syntax and structure of C++ is essential for writing effective C++ programs. This guide covers the fundamental elements of C++ syntax and how to structure a C++ program.

## Basic Syntax

### Hello World Example

The simplest C++ program is a "Hello, World!" application. Here's what it looks like:

```cpp
#include <iostream>

int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
```

### Explanation

- **Header File**: The `#include <iostream>` line includes the input/output stream library, allowing us to use `cout` and `endl`.
- **Main Function**: The `main` function is the entry point of any C++ application. It returns an integer value (`int`) indicating the exit status.
- **Output Statement**: The `std::cout << "Hello, World!" << std::endl;` statement prints the specified message to the console.

## Comments

Comments are used to explain code and are ignored by the compiler.

- **Single-line comments** start with `//`.

```cpp
// This is a single-line comment
```

- **Multi-line comments** are enclosed in `/* ... */`.

```cpp
/*
This is a multi-line comment
that spans multiple lines.
*/
```

## Data Types and Variables

C++ supports various data types such as `int`, `double`, `char`, `bool`, etc., and allows the declaration of variables using the syntax `datatype variableName;`.

```cpp
int age = 25;
double salary = 50000.50;
char grade = 'A';
bool isEmployed = true;
```

## Control Structures

C++ provides control structures like `if`, `else`, `for`, `while`, and `switch` for conditional and looping operations.

```cpp
if (age >= 18) {
std::cout << "You are an adult." << std::endl;
} else {
std::cout << "You are a minor." << std::endl;
}
```

## Functions

Functions in C++ are declared using the syntax `returnType functionName(parameters) { ... }`.

```cpp
int add(int a, int b) {
return a + b;
}

int result = add(5, 10); // result = 15
```

## Conclusion

Understanding the basic syntax and structure of C++ is foundational to becoming proficient in C++ programming. By mastering these concepts, you can write efficient and reliable C++ code for various applications.
47 changes: 46 additions & 1 deletion docs/cpp/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,49 @@ sidebar_label: Overview
sidebar_position: 1
tags: [C++, overview]
description: In this tutorial, you will learn about the C++ programming language, its features, and its applications.
---
---

C++ is a high-level, general-purpose programming language that is widely used for developing system software, application software, game development, and more. It is an extension of the C programming language with additional features such as classes and objects, inheritance, polymorphism, and templates.

## What we will learn in this tutorial?

In this tutorial, you will learn about the C++ programming language, its features, and its applications. You will also learn how to set up a C++ development environment on your computer and write your first C++ program.

## What is C++?

- C++ is a high-level, general-purpose programming language.
- It is an extension of the C programming language with additional features such as classes and objects, inheritance, polymorphism, and templates.
- C++ is designed for system programming, application development, game development, and more.
- It is a statically typed language, which means that variable types are checked at compile time.
- C++ supports both procedural programming and object-oriented programming paradigms.
- C++ code is typically compiled into machine code for execution.

## Features of C++

- **Object-Oriented**: C++ is an object-oriented programming language. It supports the concepts of classes and objects, inheritance, polymorphism, and encapsulation.
- **Statically Typed**: C++ is a statically typed language, which means that variable types are checked at compile time.
- **Compiled Language**: C++ code is compiled into machine code for execution, which can result in high performance.
- **Portable**: C++ code can be compiled and executed on different platforms, making it portable.
- **Memory Management**: C++ allows manual memory management using pointers, which gives developers more control over memory allocation and deallocation.
- **Standard Library**: C++ provides a rich standard library that includes data structures, algorithms, input/output functions, and more.
- **Compatibility with C**: C++ is compatible with C code, allowing developers to use existing C libraries and code in C++ programs.

## Applications of C++

C++ is used in a wide range of applications, including:

- **System Software**: C++ is used to develop system software such as operating systems, device drivers, and firmware.
- **Application Software**: C++ is used to develop application software such as desktop applications, business applications, and productivity tools.
- **Game Development**: C++ is widely used in game development. It is used to build game engines, game logic, and graphics rendering.
- **Embedded Systems**: C++ is used in embedded systems development. It is used to build embedded software for devices such as microcontrollers, IoT devices, and automotive systems.
- **High-Performance Computing**: C++ is used in high-performance computing (HPC) applications such as scientific computing, simulations, and data analysis.
- **Graphics Programming**: C++ is used in graphics programming. It is used to develop graphics libraries, rendering engines, and graphical user interfaces (GUIs).
- **Financial Applications**: C++ is used in financial applications such as trading systems, risk management software, and financial modeling tools.
- **Compiler Development**: C++ is used to develop compilers, interpreters, and language tools for other programming languages.
- **Networking**: C++ is used in networking applications such as network protocols, servers, and communication software.
- **Artificial Intelligence**: C++ is used in artificial intelligence (AI) applications such as machine learning algorithms, neural networks, and AI research.
- **Multimedia Applications**: C++ is used in multimedia applications such as audio/video processing, image processing, and media players.

## Conclusion

C++ is a powerful and versatile programming language that is widely used in various domains. It combines the features of procedural programming with object-oriented programming, making it suitable for a wide range of applications. Whether you are a beginner or an experienced developer, learning C++ can open up opportunities to work on exciting projects and technologies. In this tutorial, you will learn the basics of C++ programming and how to get started with C++ development. Let's dive in!
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,45 @@ sidebar_label: Setup C++ Development Environment
sidebar_position: 3
tags: [c++, setup c++ development environment]
description: In this tutorial, you will walk through all the steps of setting up a C++ development environment on your local computer.
---
---

# Setting Up a C++ Environment

## Introduction

Before you can start programming in C++, you need to set up your development environment. This typically involves installing the necessary software and configuring your system to compile and run C++ code.

## Steps to Set Up C++ Environment

1. **Install a C++ Compiler**:

- For Windows, you can install MinGW or Microsoft Visual C++ Compiler.
- For macOS, you can install Xcode Command Line Tools or use Homebrew to install GCC.
- For Linux, you can use your package manager to install GCC or Clang.

2. **Choose a Text Editor or Integrated Development Environment (IDE)**:

- Choose a text editor like Visual Studio Code, Sublime Text, or Atom, or an IDE like Visual Studio or CLion for C++ development.
- Download and install the chosen editor or IDE from their official websites.

3. **Set Up Compiler and Build Tools**:

- If using an IDE, configure it to use the installed C++ compiler (e.g., GCC or Clang).
- For text editors, install C++ language support extensions or plugins for syntax highlighting and code completion.

4. **Install C++ Libraries and Frameworks** (Optional but recommended):

- Depending on your project requirements, install any necessary C++ libraries or frameworks like Boost, Qt, or OpenGL.
- Configure your development environment to include these libraries in your project.

5. **Verify Installation**:

- Open a terminal or command prompt and type `g++ --version` (for GCC) or `clang++ --version` (for Clang) to verify that the C++ compiler is installed and accessible.

6. **Set Up Environment Variables** (Optional but recommended):

- Set up environment variables such as `PATH` to include the directory containing the C++ compiler and build tools, allowing you to run C++ commands from any directory in the terminal or command prompt.

## Conclusion

Setting up a C++ environment is crucial for C++ developers to compile, run, and manage C++ applications effectively. By following these steps and choosing the right tools for your needs, you can create a well-configured development environment that enhances your productivity and workflow when working with C++ code.
41 changes: 40 additions & 1 deletion docs/cpp/introduction-to-cpp/what-is-cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,43 @@ sidebar_label: What is C++?
sidebar_position: 1
tags: [c++, what is c++, introduction to c++]
description: In this tutorial, you will learn about the C++ programming language, what it is, its features, and its applications.
---
---

# Introduction to C++

## What is C++?

C++ is a powerful and widely-used programming language known for its versatility, performance, and extensive feature set. It is an extension of the C programming language with additional features such as classes and objects, inheritance, polymorphism, templates, and more. C++ is designed for system programming, application development, game development, and other domains.

## Key Features of C++

- **Object-Oriented**: C++ is an object-oriented programming (OOP) language, allowing developers to create classes and objects that encapsulate data and behavior.
- **Statically Typed**: C++ is a statically typed language, meaning that variable types are checked at compile time for type safety.
- **Compiled Language**: C++ code is compiled into machine code for execution, resulting in high performance and efficiency.
- **Memory Management**: C++ allows manual memory management using pointers, giving developers control over memory allocation and deallocation.
- **Standard Library**: C++ provides a rich standard library with data structures, algorithms, input/output functions, and more, facilitating software development.
- **Compatibility with C**: C++ is compatible with C code, allowing developers to use existing C libraries and code in C++ programs.

## C++ Development Ecosystem

C++ has a comprehensive development ecosystem comprising various tools, libraries, and frameworks:

- **Integrated Development Environments (IDEs)**: Popular IDEs for C++ development include Visual Studio, Code::Blocks, and CLion, offering features like code completion, debugging, and project management.

- **Libraries and Frameworks**: C++ has numerous libraries and frameworks for different purposes, such as Boost for general-purpose programming, Qt for GUI development, and OpenGL for graphics programming.

- **Community Support**: C++ has a vibrant community of developers who contribute to open-source projects, share knowledge through forums and blogs, and provide support to fellow developers.

## C++ Editions

C++ has evolved over time, leading to different editions tailored for specific platforms and use cases:

- **Standard C++**: Also known as ISO C++, this is the standardized version of the language maintained by the International Organization for Standardization (ISO).

- **C++11, C++14, C++17, C++20**: These are versions of the language that introduce new features and improvements, enhancing productivity and code quality.

- **Embedded C++ (EC++)**: Optimized for embedded systems development, EC++ focuses on efficiency, low-level programming, and resource-constrained environments.

## Conclusion

C++ continues to be a preferred choice for developers due to its versatility, performance, and extensive ecosystem. Whether you are building system software, applications, games, or embedded systems, C++ offers the tools and capabilities to meet diverse development needs. Its object-oriented nature, strong memory management, and compatibility with C make it a robust and reliable language for a wide range of projects.
Loading
Loading