Click on a topic to expand and learn in detail.
C++ is a high-performance programming language widely used in system programming, games, and applications.
#include <iostream>
using namespace std;
int main() {
cout << "Hello World";
return 0;
}
int age = 25;
float pi = 3.14;
char grade = 'A';
bool flag = true;
string name = "Alice";
// Arithmetic: +, -, *, /, %
int sum = 5 + 3;
// Comparison: ==, !=, >, <
bool result = (5 > 3); // true
// Logical: &&, ||, !
bool flag = true && false; // false
int age = 18;
if(age >= 18){
cout << "Adult";
} else {
cout << "Minor";
}
switch(age){
case 18:
cout << "Exactly 18";
break;
default:
cout << "Other";
}
// for loop
for(int i=0;i<5;i++){
cout << i;
}
// while loop
int i=0;
while(i<5){
cout << i;
i++;
}
// do-while loop
int j=0;
do{
cout << j;
j++;
}while(j<5);
int add(int a, int b){
return a+b;
}
int main(){
cout << add(5,3);
return 0;
}
int numbers[5] = {1,2,3,4,5};
cout << numbers[0]; // 1
string name = "Alice";
cout << name;
int x = 10;
int *ptr = &x;
cout << *ptr; // 10
int &ref = x;
ref = 20;
cout << x; // 20
class Person{
public:
string name;
int age;
void greet(){
cout << "Hello " << name;
}
};
int main(){
Person p;
p.name = "Alice";
p.age = 25;
p.greet();
return 0;
}
#include <fstream>
ofstream outFile("data.txt");
outFile << "Hello C++";
outFile.close();
ifstream inFile("data.txt");
string text;
inFile >> text;
cout << text;