Getting started with C++
Your first program, input and output with streams, and references.
C++ builds on C, adding classes and a rich standard library. Compile with g++ -std=c++17 main.cpp -o main.
C++
#include <iostream>
#include <string>
using namespace std;
int main() {
string name = "Erode";
int year = 2026;
cout << "Vanakkam, " << name << " " << year << "\n";
return 0;
}Output
Vanakkam, Erode 2026
References
A reference is another name for an existing variable. It gives you the effect of a pointer with simpler syntax.
C++
#include <iostream>
using namespace std;
void addBonus(int &marks) {
marks += 5;
}
int main() {
int m = 70;
addBonus(m);
cout << m << "\n";
return 0;
}Output
75