C++ Basics Guide
1. Overview of C++
C++ is a general-purpose programming language developed by Bjarne Stroustrup as an extension of the C language. It provides exceptionally powerful support for Object-Oriented Programming (OOP) and Generic Programming (Templates).
2. Writing a Simple Program
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
3. Pointers and References
C++ offers pointers for manual memory management and more intuitive "references" to interact with values directly.
int a = 10;
int& ref = a; // Reference for variable 'a'
ref = 20;
cout << a; // Output: 20
4. Object-Oriented Programming (Classes and Methods)
class Animal {
private:
string name;
public:
Animal(string n) : name(n) {} // Constructor
void Speak() {
cout << name << " makes a sound." << endl;
}
};
Animal myDog("Buddy");
myDog.Speak();