History
- C++ is a cross-platform language that can be used to create a high-performance applications.
- C++ was developed by Bjarne Stroustrup, in 1979 at bell Labs as an extension to the the C as a Low-Level Language .
- C++ gives programmers a high level of control over system resources and memory.
- The language was updated multiple times leading to various C++11, C++14, C++17, C++20, C++23.
Applications
- C++ can be found in code of operating systems
- Graphical User Interfaces and embedded systems
- Many gaming engines are written in C++
- Web browsers like Mozilla, Chrome are written in C++
- Banking applications Libraries & Frameworks for Machine learning like tensor-flow by google.
Deep dive into the Boilerplate code:
Boilerplate code:
include<iostream>
using namespace std;
int main(){
//your code goes here
cout << "Hello World";
return 0;
}
#include
: Pre-processor Directive : Gives instruction to the compiler for the pre-processing of the code.
iostream
: Header file : For adding additional functionality in your code using a pre-written code file.
using namespace std
: C++ standard namespace like cout
, cin
etc.
cout
: Cout object : We want to output something in the console or the terminal.
int main()
: Functions : Entry point : program starts executing from the main & any logic that you will define will go in the main. Each function will return something.
return 0
: defines successful execution of the main function.
NOTE
Compilation happens for every line which is line 1 - 7. Execution happens for line 4 - 7.
Input -Output
Variables
To store data from user input we need to create buckets in the memory, the buckets are called variables. Each variable is of a certain datatype.
#include<iostream>
using namespace std;
int main(){
//creating variables
int a, b, c;
//reading inputs
cin >> a;
cin >> b;
cin >> c;
## outputs
cout << "A:" << a << "B:" << b << "C:" << c << endl;
//sum
int sum = a + b + c;
cout << sum << endl;
// optional : cout << (a + b + c) << endl;
return 0;
}
FAQ
C++ is a case sensitive language.
Comments
Single line comment :
// this is a comment
Multi line comment :
/*
This is a multi line
commment in C++
*/