Introduction to C++

Jun 30, 2024

First C++ Program Lecture Notes

Introduction

  • C++: A fast language, commonly used in advanced graphics, embedded systems, and video games.
    • Middle-level language: Close to hardware but also resembles human language.

Why Learn C++?

  • High performance in graphics-intensive applications (e.g., Adobe software, video editing, games).
  • Requires more effort to write compared to higher-level languages (Python, Java) but offers speed and hardware control.
  • Learning Curve: Initial difficulty but rewarding.

Getting Started

Tools Required:

  1. Text Editor/IDE: Examples include VS Code, Code::Blocks, or even Notepad.
    • VS Code and Code::Blocks are IDEs (text editor + developer tools).
  2. Compiler: Converts source code to machine instructions.
    • For Windows/Linux: GCC recommended.
    • For Mac: Clang recommended.
    • Installation varies by OS.

Installation of VS Code and Compiler

  1. Download VS Code: Go to code.visualstudio.com, download for your OS, and install it.
  2. Install Extensions: In VS Code, install the C/C++ and Code Runner extensions.
  3. Folder Setup: Create and open a folder for your C++ projects.
  4. Install Compiler:
    • Linux: Use terminal commands to install GCC.
    • Mac: Use terminal to install Clang.
    • Windows: Install MinGW. Follow steps to integrate it with VS Code.

Writing Your First Program

Hello World Program

  1. Create hello_world.cpp file in your C++ projects folder.
  2. Include Header File: #include <iostream> for input/output operations.
  3. Main Function: int main() { ... }, where the program execution begins.
  4. Output Statement: Use std::cout to print