0% found this document useful (0 votes)
6 views4 pages

Complete CPP Notes

This document provides a comprehensive overview of C++ programming concepts, including program structure, fundamental types, object-oriented programming essentials, and memory management. It emphasizes the importance of modern practices such as RAII, smart pointers, and the use of STL algorithms and containers while highlighting common pitfalls. Key features from various C++ standards (C++11, C++14, C++17, C++20) are also summarized, along with important headers and interview tips.

Uploaded by

creator2463
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Complete CPP Notes

This document provides a comprehensive overview of C++ programming concepts, including program structure, fundamental types, object-oriented programming essentials, and memory management. It emphasizes the importance of modern practices such as RAII, smart pointers, and the use of STL algorithms and containers while highlighting common pitfalls. Key features from various C++ standards (C++11, C++14, C++17, C++20) are also summarized, along with important headers and interview tips.

Uploaded by

creator2463
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Complete C++ Notes (Compact — 4–5 pages)

Program Structure & Basics


Element Notes

Headers #include <iostream>, <vector>, <string>, etc.

main() signature int main(), int main(int argc, char** argv) — `void main()` is non-standard

Namespaces namespace X {}; using namespace std; (avoid in headers)

Linkage internal (static / anonymous ns) vs external (extern)

Fundamental Types
Category Types / Notes

Integral bool, char, signed/unsigned char, short, int, long, long long

Fixed-width <cstdint>: int8_t, uint32_t, int64_t, etc.

Character types char, signed/unsigned char, wchar_t, char16_t, char32_t, char8_t (C++20)

Floating float, double, long double

Special void, nullptr_t, size_t, ptrdiff_t, std::byte (C++17)

Type Modifiers & Qualifiers


Qualifier Effect

const immutable interface; const T*, T* const, const T* const

volatile special memory reads/writes (rarely used)

mutable allow modification in const methods

constexpr compile-time constant (constexpr functions/variables)

inline suggest inline; inline variables (C++17)

thread_local per-thread storage (C++11)

Storage Duration & Linkage


Term Description

Automatic local variables; destroyed on scope exit

Static static storage lifetime — program duration

Dynamic allocated with new/malloc; freed with delete/free

Thread thread_local objects — per-thread lifetime

Operators & Casts


Category Notes

C-like ops arithmetic, logical, bitwise, relational

Member ., ->, :: (scope resolution), .* and ->* (pointer-to-member)

New/Delete new/delete, new[]/delete[] — matching required

C++ casts static_cast, reinterpret_cast, const_cast, dynamic_cast

Other sizeof, typeid, noexcept, alignof

OOP Essentials
Concept Notes

class vs struct default access: class=private, struct=public

Access specifiers public, protected, private

Inheritance public/protected/private; virtual inheritance for diamond

Virtual functions enable runtime polymorphism; use virtual destructor

Pure virtual virtual void f()=0 -> abstract class

Object slicing copying derived to base by value loses derived part

Special Member Functions & Rule of Three/Five/Zero


Function Notes

Default ctor ClassName()

Copy ctor ClassName(const ClassName&)

Copy assign ClassName& operator=(const ClassName&)

Move ctor ClassName(ClassName&&) noexcept

Move assign ClassName& operator=(ClassName&&) noexcept

Dtor ~ClassName()

Rule If you manage resources, implement copy/move/dtor (Three/Five)

Constructors / Initializers
Feature Notes

Member init list A:int x; Ctor():x(0){} — preferred

Delegating ctors C++11: one ctor calls another

explicit prevents implicit conversions

default/delete =default, =delete (C++11)

References & Rvalues


Concept Notes

Lvalue ref T& binds to lvalues

Const ref const T& binds to rvalues

Rvalue ref T&& for move semantics, temporary binding

std::move casts to rvalue to enable moves

Perfect forwarding template<typename T> f(T&&); use std::forward<T>(t)

Move Semantics & Resource Mgmt


Idea Notes

Move ctor/assign steal resources; set source to valid-empty state

Smart pointers std::unique_ptr, std::shared_ptr, std::weak_ptr; use make_unique/make_shared

RAII resource acquisition is initialization — manage lifetime in objects

Templates & Metaprogramming


Feature Notes

Function/Class templates template<typename T> T max(T a, T b){}

Specialization full and partial specialization

Variadic templates template<typename... Args>

SFINAE & type traits enable_if, std::is_same, std::decay, <type_traits>

Concepts (C++20) template constraints with `requires`

Lambda & Functional


Feature Notes

Syntax [captures](params)->ret{body};

Captures &, =, this, [a, &b], mutable for modifying captured by value

std::function type-erased callable wrapper (costly)

std::bind partial application (less used vs lambdas)

STL Containers — Key Notes


Container Notes/Complexity & Invalidations

vector dynamic array, contiguous, random-access; push_back amortized O(1); insert invalidates iterators when reallocation

deque double-ended, random access, non-contiguous blocks

list doubly-linked; splicing O(1)

forward_list singly-linked
Container Notes/Complexity & Invalidations

array std::array<T,N> fixed-size wrapper

string std::string — contiguous; use +, append, emplace_back

set/map ordered associative containers; logarithmic ops

unordered_map/set hash-based; average O(1)

stack/queue/priority_queue adapters over other containers

Iterators & Algorithms


Concept Notes

Iterator categories input, output, forward, bidirectional, random-access

std::begin/end range-based for uses these; use std::cbegin for const

Algorithms <algorithm>: sort, partial_sort, nth_element, find, binary_search, accumulate

Complexities check docs; prefer algorithms over hand loops for correctness

I/O & File Streams


Header Notes

iostream std::cin, std::cout, std::cerr; use std::ios::sync_with_stdio(false) for speed

fstream std::ifstream, std::ofstream, std::fstream

sstream std::istringstream, std::ostringstream for string streams

Exceptions & noexcept


Feature Notes

throw throw expr; avoid throwing in destructors

catch catch by const reference: catch(const std::exception& e)

noexcept declare functions that don't throw; noexcept(true/false)

std::exception base class; derive custom exceptions

Concurrency (basics)
Feature Notes

thread std::thread to launch threads

mutex std::mutex, lock_guard, unique_lock

atomic std::atomic<T> for lock-free primitives

future/promise std::future, std::promise, async

Preprocessor & Build


Feature Notes

Macros #define — avoid complex macros; prefer inline/constexpr/templates

Include guards #ifndef/#define or #pragma once

One Definition Rule ODR violations -> undefined behavior

Common Gotchas & Interview Tips


Topic Notes

struct/class default access struct=public, class=private

virtual dtor delete base* p when polymorphic -> base dtor must be virtual

copy elision RVO/NRVO — copy may be elided (C++17 mandatory in some cases)

iterator invalidation vector reallocation invalidates iterators/pointers

dangling ref/pointer don't return local references/pointers

sizeof returns bytes for types; be careful with arrays decaying to pointers

endian/UB undefined behavior not guaranteed to crash; avoid relying on behavior

C++ Standard Highlights (11/14/17/20)


Std Key features

C++11 auto, nullptr, rvalue refs, move, lambda, constexpr(1.0), range-based for, override/final

C++14 generalized constexpr, return type deduction, make_unique

C++17 structured bindings, if constexpr, inline variables, std::optional, std::variant, string_view

C++20 concepts, ranges, coroutines, modules, constexpr expands, char8_t

Important Headers (brief)


Header Purpose

<iostream> I/O streams

<vector>,<deque>,<list> sequence containers

<map>,<set>,<unordered_map> associative containers

<algorithm> algorithms

<memory> smart pointers

<thread>,<mutex>,<atomic> concurrency

<type_traits> type utilities

<functional> function wrappers, bind, mem_fn

Flowing Summary (tiny):


C++ is a multi-paradigm language built on C with object-orientation and generic programming. Use RAII and smart pointers to manage resources, prefer STL algorithms &
containers, avoid raw new/delete where possible, and follow Rule of Zero/Three/Five for resource-owning types. Understand move semantics (rvalue refs, std::move), ownership
models (unique/shared/weak), and common pitfalls: slicing, UB from dangling refs, iterator invalidation, and undefined behavior from ODR violations. Keep code modern: prefer , , ,
use constexpr and noexcept where applicable, and minimize macros. For interviews: know copy/move constructors, virtual dispatch, templates, lambda captures, and complexity
guarantees of STL operations.

You might also like