Top 50 C++ Keywords & Functions
#CPP #Basics #IO
#1.
A preprocessor directive that includes the input/output stream library.
#2.
The main function where program execution begins.
#3.
Used to output data (print to the console).
#4.
Used to get input from the user.
#5.
Tells the compiler to use the
---
#CPP #DataTypes #Variables
#6.
Declares an integer variable.
#7.
Declares a floating-point number variable (can hold decimals).
#8.
Declares a character variable.
#9.
Declares a boolean variable, which can only have the value
#10.
Declares a variable that can hold a sequence of characters. Requires
---
#CPP #Keywords #Operators
#11.
Declares a variable as a constant, meaning its value cannot be changed.
#12.
An operator that returns the size (in bytes) of a data type or variable.
  #CPP #Basics #IO
#1.
#include <iostream>A preprocessor directive that includes the input/output stream library.
#include <iostream>
int main() {
std::cout << "This requires iostream!";
return 0;
}
This requires iostream!
#2.
int main()The main function where program execution begins.
#include <iostream>
int main() {
std::cout << "Program starts here.";
return 0;
}
Program starts here.
#3.
std::coutUsed to output data (print to the console).
#include <iostream>
int main() {
std::cout << "Hello, C++!";
return 0;
}
Hello, C++!
#4.
std::cinUsed to get input from the user.
#include <iostream>
#include <string>
int main() {
int age;
std::cout << "Enter your age: ";
std::cin >> age;
std::cout << "You are " << age << " years old.";
return 0;
}
Enter your age: 25
You are 25 years old.
#5.
using namespace std;Tells the compiler to use the
std (standard) namespace. Avoids prefixing std:: to every standard function.#include <iostream>
using namespace std;
int main() {
cout << "No std:: prefix needed.";
return 0;
}
No std:: prefix needed.
---
#CPP #DataTypes #Variables
#6.
intDeclares an integer variable.
#include <iostream>
int main() {
int number = 100;
std::cout << "The number is: " << number;
return 0;
}
The number is: 100
#7.
doubleDeclares a floating-point number variable (can hold decimals).
#include <iostream>
int main() {
double price = 19.99;
std::cout << "The price is: " << price;
return 0;
}
The price is: 19.99
#8.
charDeclares a character variable.
#include <iostream>
int main() {
char grade = 'A';
std::cout << "Your grade is: " << grade;
return 0;
}
Your grade is: A
#9.
boolDeclares a boolean variable, which can only have the value
true or false.#include <iostream>
int main() {
bool isRaining = false;
std::cout << "Is it raining? " << isRaining; // Outputs 0 for false
return 0;
}
Is it raining? 0
#10.
std::stringDeclares a variable that can hold a sequence of characters. Requires
#include <string>.#include <iostream>
#include <string>
int main() {
std::string greeting = "Hello, World!";
std::cout << greeting;
return 0;
}
Hello, World!
---
#CPP #Keywords #Operators
#11.
constDeclares a variable as a constant, meaning its value cannot be changed.
#include <iostream>
int main() {
const double PI = 3.14159;
std::cout << "The value of PI is: " << PI;
// PI = 4; // This would cause a compile error
return 0;
}
The value of PI is: 3.14159
#12.
sizeof()An operator that returns the size (in bytes) of a data type or variable.
#include <iostream>
int main() {
int myInt;
std::cout << "Size of int is: " << sizeof(myInt) << " bytes.";
return 0;
}
Size of int is: 4 bytes.