int x = 10; | Integer (4 bytes) |
float f = 3.14f; | Float (4 bytes) |
double d = 3.14159; | Double (8 bytes) |
char c = 'A'; | Character (1 byte) |
char str[] = "hello"; | String (char array) |
int arr[5] = {1,2,3,4,5}; | Array declaration |
const int MAX = 100; | Constant |
int *ptr = &x; | Pointer to int |
*ptr = 20; | Dereference pointer |
ptr++; | Pointer arithmetic |
int **pp = &ptr; | Pointer to pointer |
void *vp; | Void pointer |
int (*fp)(int); | Function pointer |
malloc(size) | Allocate memory |
calloc(n, size) | Allocate and zero |
realloc(ptr, size) | Reallocate memory |
free(ptr) | Free memory |
sizeof(type) | Size of type |
std::cout << "text" << std::endl; | Print to stdout |
std::cin >> variable; | Read from stdin |
std::getline(std::cin, str); | Read line |
std::string s = "hello"; | String type |
s.length() / s.size() | String length |
s.substr(pos, len) | Substring |
s.find("text") | Find substring |
int *p = new int; | Allocate single |
int *arr = new int[10]; | Allocate array |
delete p; | Delete single |
delete[] arr; | Delete array |
std::unique_ptr<T> | Unique smart pointer |
std::shared_ptr<T> | Shared smart pointer |
std::make_unique<T>(args) | Create unique_ptr |
std::make_shared<T>(args) | Create shared_ptr |
int &ref = x; | Lvalue reference |
int &&rref = 10; | Rvalue reference |
const int &cref = x; | Const reference |
std::move(obj) | Move semantics |
std::forward<T>(arg) | Perfect forwarding |
class MyClass { }; | Class definition |
public: | Public access |
private: | Private access |
protected: | Protected access |
MyClass() { } | Constructor |
~MyClass() { } | Destructor |
MyClass(const MyClass&) | Copy constructor |
MyClass(MyClass&&) | Move constructor |
class Derived : public Base | Public inheritance |
virtual void func() | Virtual function |
virtual void func() = 0 | Pure virtual |
override | Override specifier |
final | Final specifier |
dynamic_cast<T*>(ptr) | Runtime cast |
T operator+(const T& rhs) | Binary operator |
T& operator=(const T& rhs) | Assignment operator |
bool operator==(const T& rhs) | Equality operator |
T& operator[](size_t i) | Subscript operator |
operator T() | Conversion operator |
std::vector<T> | Dynamic array |
std::array<T, N> | Fixed array |
std::deque<T> | Double-ended queue |
std::list<T> | Doubly linked list |
std::forward_list<T> | Singly linked list |
std::set<T> | Ordered unique set |
std::multiset<T> | Ordered multiset |
std::map<K, V> | Ordered key-value |
std::multimap<K, V> | Ordered multimap |
std::unordered_set<T> | Hash set |
std::unordered_map<K, V> | Hash map |
v.push_back(x) | Add to end |
v.emplace_back(args) | Construct in place |
v.pop_back() | Remove from end |
v.insert(it, x) | Insert at position |
v.erase(it) | Erase at position |
v.clear() | Clear all |
v.size() | Get size |
v.empty() | Check if empty |
std::sort(begin, end) | Sort range |
std::stable_sort(begin, end) | Stable sort |
std::partial_sort(begin, mid, end) | Partial sort |
std::binary_search(begin, end, val) | Binary search |
std::lower_bound(begin, end, val) | Lower bound |
std::upper_bound(begin, end, val) | Upper bound |
std::find(begin, end, val) | Find element |
std::find_if(begin, end, pred) | Find by predicate |
std::transform(begin, end, out, func) | Transform elements |
std::copy(begin, end, out) | Copy range |
std::move(begin, end, out) | Move range |
std::fill(begin, end, val) | Fill with value |
std::reverse(begin, end) | Reverse range |
std::rotate(begin, mid, end) | Rotate range |
std::unique(begin, end) | Remove consecutive duplicates |
std::accumulate(begin, end, init) | Sum elements |
std::inner_product(b1, e1, b2, init) | Inner product |
std::partial_sum(begin, end, out) | Partial sums |
std::min_element(begin, end) | Find minimum |
std::max_element(begin, end) | Find maximum |
std::count(begin, end, val) | Count occurrences |
auto x = 10; | Auto type deduction |
decltype(expr) | Deduce type from expr |
auto func() -> int | Trailing return type |
auto [a, b] = pair; | Structured binding (C++17) |
[](int x) { return x*2; } | Basic lambda |
[=](int x) { } | Capture by value |
[&](int x) { } | Capture by reference |
[this](int x) { } | Capture this |
[x=std::move(y)]() { } | Init capture (C++14) |
[]<typename T>(T x) { } | Generic lambda (C++20) |
std::thread t(func, args); | Create thread |
t.join(); | Wait for thread |
t.detach(); | Detach thread |
std::mutex mtx; | Mutex |
std::lock_guard<std::mutex> lock(mtx); | RAII lock |
std::async(std::launch::async, func) | Async execution |
std::future<T> | Future result |
std::atomic<T> | Atomic type |
concept MyConcept = ...; | Define concept |
requires (T x) { ... } | Requires clause |
std::ranges::sort(v) | Ranges algorithm |
v | std::views::filter(pred) | Views pipeline |
co_await expr | Coroutine await |
co_yield value | Coroutine yield |
std::span<T> | Non-owning view |
auto operator<=>(const T&) = default; | Three-way comparison |
template<typename T> | Template declaration |
template<typename T, typename U> | Multiple type params |
template<int N> | Non-type parameter |
template<typename... Args> | Variadic template |
template<> class MyClass<int> | Full specialization |
template<typename T> class MyClass<T*> | Partial specialization |
std::is_same_v<T, U> | Check same type |
std::is_integral_v<T> | Check integral |
std::is_pointer_v<T> | Check pointer |
std::remove_reference_t<T> | Remove reference |
std::decay_t<T> | Decay type |
std::enable_if_t<cond, T> | SFINAE helper |