📅  最后修改于: 2023-12-03 15:13:53.984000             🧑  作者: Mango
This cheat sheet will provide you with the most important concepts and syntax of C++ programming language. It is a quick reference guide for beginner and intermediate level programmers who need to quickly check the syntax or concepts.
A variable is a container that stores a value. It can be of different data types such as int, char, float, double, etc.
// Variable declaration
int age;
float weight;
char initial;
Following are the data types in C++:
// Data Type declaration
int num1 = 10;
float num2 = 3.14;
double num3 = 3.141592653589793;
char letter = 'A';
bool flag = true;
Conditional statements are used to execute a block of code based on some condition.
// If-else statement
if(condition) {
// Code to be executed if condition is true
} else {
// Code to be executed if condition is false
}
Loops are used to execute a block of code repeatedly until a certain condition is met.
// For loop
for(initialization; condition; increment) {
// Code to be executed
}
// While loop
while(condition) {
// Code to be executed
}
// Do-While loop
do {
// Code to be executed
} while(condition)
Functions are a block of code that performs a specific task. It can be called multiple times from different parts of the program.
// Function Declaration
return_type function_name(parameters)
{
// Code to be executed
}
// Function Call
function_name(argument_values)
An array is a collection of similar data types. It is a fixed-size container that stores multiple values of the same data type.
// Array declaration
data_type array_name[size];
// Example
int numbers[5] = {1, 2, 3, 4, 5};
A string is a collection of characters. It is actually an array of characters terminated by a NULL character (\0).
// String declaration
string str = "Hello World";
A pointer is a variable that stores the memory address of another variable. It is used to access and manipulate the value of the variable indirectly.
// Pointer declaration
data_type *var_name;
// Example
int num = 10;
int *ptr = #
// Dereferencing
cout << *ptr << endl;
// Output: 10
A class is a user-defined data type that encapsulates data and functions together. An object is an instance of a class.
// Class declaration
class class_name
{
access_specifier:
data_type data_member1;
data_type data_member2;
function_type function_name();
}
// Object creation
class_name obj;
// Input
cin >> variable_name;
// Output
cout << "Text/Value" << endl;
This cheat sheet covers the most important concepts and syntax of C++ programming language. It can serve as a quick reference guide for beginner and intermediate level programmers.