PulthApp

Beginner friendly C++ introduction

Table of Contents:

  • Introduction
  • Setting up
  • Basic Operations
  • Datatypes

Introduction

What is C++?

C++ is a programming language created by Bjarne Stroustrup in 1985. It is an object-oriented programming language used for general purposes created to be an extension of its predecessor C and it provides features such as classes and inheritance. It is a popular language used for coding games. Examples include GTA Vice City, Counter-Strike, and Angry Birds. It is also widely used in system programming and high-performance computing.

This programming language has a library called C++ standard library, which includes a lot of algorithms, data structures, and functions.

As I said earlier, C++ supports OOP or Object Oriented Programming which allows you to write programs with classes and objects that result in better organization of your code.

Setting up 

These are the list of things you need before you can start coding.

  • Compiler - converts your code into an executable file that your computer can run. ( I recommend Visual Studio Code which already includes a compiler provided by Microsoft)
  • Select your version and run the installer, adding the bin folder inside the directory of your system's path.
  • You want to confirm that the compiler is installed and working, so open up your command prompt or cmd and enter this command ( g++ --version )

"Hello, World!" is the first program that people run in any programming language when they are starting out. Down below is how you achieve that.

#include <iostream>

int main() {

std::cout << "Hello, World!" << std::endl;

return 0;

}

#include <iostream> - This is a directive that tells the compiler to include iostream enabling you to create functions and declare classes that you can use for your programs.

int main(){} - This is the entry point of your program, this should only be defined once and should return an integer.

std::cout << "Hello, World!" << std::endl; 

std::cout - is used for output

"Hello, World!" - is the string to print

std::endl; - this tells the compiler to endline and insert a newline character 

return 0; - this tells the compiler that the program has been executed successfully, returning any other number results in an error.

Basic Operations

  • Addition - int sum = a + b;
  • Subtraction - int difference = a - b;
  • Multiplication - int product = a * b;
  • Division - int quotient = a / b;
  • Modulus - int remainder = a % b;
  • Increment - int y = ++x;
  • Decrement - int y = --x;
  • AND - &&
  • OR - ||
  • NOT - !
  • For loop - for (initialization; condition; increment/decrement) {}
  • While loop - while (condition) {}
  • Do while - do {} while (condition);

Data Types

Static typing - this means that the data type is determined before the program is executed.

For example int num = 7 ( the variable 7 is an integer defined by int) and so on.

Dynamic typing - data type is determined at compile time

Void Pointers - a pointer that points to any data type, used to reference any type of object without knowing the specifics.

.,

1

4 views
Iduka Naranbaatar

Iduka Naranbaatar

1 Comments


https://lh3.googleusercontent.com/a/AGNmyxYuXOJgJCiMwACsjlDPA_slZ3116j1TgHMEfAAB=s96-c profile image
Bekir Gülestan

https://google.com say hello