📓
Everything I Know
  • index
  • #
    • 3D Printing
  • A
    • Abandoned Spaces
    • ADHD
    • Aging
    • Algorithms & Data Structures
      • Array
      • Constraint Satisfaction Problem
      • Dynamic Programming
      • Graph
      • Hash Table
      • Heap
      • Linked List
      • Queue
      • Recursion
      • Set
      • Stack
      • Tree
      • Trie
      • Union Find
    • Amazon Web Services
    • Android
    • Anime, Comics & Manga
    • APIs
    • Artificial Intelligence
    • Assembly
      • ARM
      • MIPS
      • x86
    • Audio / Video Editing
    • Awesome
    • Azure
  • B
    • Board Games
    • Books
  • C
    • C (programming language)
    • C++
    • Cars
    • Cascading Style Sheets
    • Chess
    • Comedy
    • Command Line
      • Autotools
      • Awk
      • Bash scripting
      • Grep
      • Lsof
      • Sed
      • SSH
    • Competitive Programming
    • Compilers
    • Computer Graphics
      • OpenGL
      • Vulkan
      • WebGPU
    • Computer Networks
    • Computer Science
    • Concurrency
    • Continuous Integration / Delivery
    • Cooking
    • Cryptography
    • Cryptocurriencies
    • Curriculum Vitae
  • D
    • Databases
      • PostgreSQL
      • SQL
      • SQLite
    • Design Patterns
    • Digital Minimalism
    • Distributed Systems
    • Docker
    • Documentaries
    • Documentation
    • Domain Name System
    • Dopamine
    • Drawing
  • E
    • eCommerce
    • Electronics
      • Repairs
    • Engineering
    • Entrepreneurship
    • Events
  • F
    • Fashion
    • Fitness
      • Exercise
      • Nutrition
      • Weight Loss
    • Focus
    • Football
  • G
    • Game Development
      • Godot
      • LibGDX
      • Unity
      • Unreal Engine
    • Git
    • Goals
    • Guitar
  • H
    • Habits
    • Happiness
    • House
      • Tradespeople
      • Buying
      • Renting
  • I
    • Interviews
      • Behavioural Interviews
      • Coding Interviews
      • System Design Interviews
  • J
    • Java
    • JavaScript
      • Astro
      • Bun
      • Electron
      • Jest
      • Node.js
      • Nue.js
      • React.js
      • Redux
      • Vue.js
    • Journaling
  • K
    • Karting
    • Knots
    • Knowledge Bases
    • Kotlin
    • Kubernetes
  • L
    • LaTeX
    • Learning
      • Drawing
      • Languages
        • Certificate of Proficiency in English
        • Japanese
      • Piano
    • Legacy Code
    • LEGO
    • Lifestyle
    • Life Hacks
    • Linux
    • LISP
  • M
    • Machine Learning
      • Deep Learning
    • MacOS
    • Maths
    • Meditation
    • Movies
    • Music
      • Music Production
      • Music Theory
  • N
    • Negotiation
    • News
  • O
    • Operating Systems
      • Linux
  • P
    • Parenting
    • Personal Finance
      • ISAs
      • Pensions
    • PHP
    • Physics
    • Podcasts
    • Procrastination
    • Productivity
    • Programming
      • Functional Programming
      • Performance
    • Prometheus
    • Psychology
    • Public Speaking
    • Purpose
    • Puzzles
    • Python
      • Django
      • Pandas
  • Q
    • Quantum Computing
    • Quotes
  • R
    • Regular Expressions
    • Relationships
    • Reverse Engineering
    • Rust
      • Cargo
  • S
    • Security
      • Android
      • Binary Exploitation
      • CompTIA Security+ SYO-701
      • CTFs
      • Forensics
      • Linux
      • Web
      • Windows
    • Self Improvement
    • Shaving
    • Sitting
    • Sleep
    • Social Skills
    • Spring (framework)
    • Stoicism
    • Strength Training
      • Deadlifts
      • Push Ups
    • Success
    • System Design
      • Site Reliability Engineering
  • T
    • Table Tennis
    • Testing
    • Thinking
    • Touch Typing
    • Travel
      • Japan
        • Fukuoka
        • Hiroshima
        • Kyoto
        • Okinawa
        • Osaka
        • Tokyo
      • London
      • Rome
    • TV Series & Programmes
    • Twitch
    • TypeScript
    • Typography
  • V
    • Virtual Tours
    • Vim
    • Video Games
      • Emulation
      • Mods
      • Music
      • Speedrunning
      • Warzone
  • W
    • Web Apps
    • Web Cams
    • Web Development
      • Selenium
      • Web Assembly
    • Windows
      • Windows Development
    • Work
      • Freelancing
      • GitHub Profile
      • Interesting Companies
      • Job Boards
      • Remote Work
      • Startup
    • Writing
Powered by GitBook
On this page
  • Notes
  • Resources
  • Books
  • Frameworks
  • GitHub repositories
  • Reddit Threads
  • Videos
  • Websites
  • YouTube playlists

Was this helpful?

  1. C

C++

Notes

  • In order to translate a C++ program (as a plain text file) into an executable program, two main operations need to happen:

    • compilation: C++ source files are converted into an intermediate format called object files;

    • linking: find where each symbol is and link them together - reconstruct a single executable application from many individual object files.

  • Pre-processor directives include:

    • #include: when the pre-processor finds this directive, it will copy and paste the contents of the file being included;

    • #define: when the pre-processor finds this directive, it will replace the macro with its definition (a macro can also have arguments);

    • #if ... #end: the processor will or will not include the portion of code between these two directives depending on whether the condition of the directive is true (1) or false (0)

  • Header files are useful to share definitions among different files, so that it is possible to use in each compilation unit (=C++ file) variables, classes, and functions defined somewhere else.

  • To avoid including multiple times the same header files (and hence definitions) in a compilation unit, there are two main techniques:

    • the #pragma once directive (non-standard but almost universally supported)

    • an include guard - usually implemented via a #ifndef ... #endif block:

// my_class.h
#ifndef MY_CLASS_H // include guard
#define MY_CLASS_H

// Contents of MyClass
// ...

#endif /* MY_CLASS_H */
  • Includes with the double quotes (e.g., #include "Log.h") are used for header files in the same directory as the source file, while includes with angular brackets (e.g., #include <iostream>) are used for standard library headers.

  • A pointer is an integer variable containing a memory address. It is possible to retrieve the address of a variable with the ampersand operator (e.g., int* ptr = &myvar) and it's possible to get back the value contained at the address stored in the pointer with the asterisk operator (e.g., int mynewvar = *ptr).

  • A reference is syntax sugar on top of pointers to make it a bit easier to work with: it is not a variable with storage requirements, but simply a reference to an existing variable. It is denoted with an ampersand next to the type (e.g., int& reference = a where a is a variable of type int). It is useful especially in function declarations to pass arguments by reference (i.e., with a pointer) rather than by value (i.e., creating a copy of the value to be used inside the function).

  • Classes allow to define types containing both data and functions (called methods) that act upon them. The only difference between a class and a struct is that, by default, all members of a class are private, while all members of a struct are public.

class Player {
public:
    int x, y;
    int speed;
    
    void Move(int xa, int ya) {
        x += xa * speed;
        y += ya * speed;
    }
};

int main() {
    Player player;
    player.Move(1, -1);
}
  • The static variable has two different meanings, depending on the context where it's used:

    • inside classes, a static variable/method will be shared among all instances of the class where the static variable is defined (NB a static method can only access static variables in its body);

    • outside classes, static means the linkage of the symbol declared as static will be limited to the translation unit (=C++ file) where it was defined.

  • The constructor is a special method of a class that gets automatically called when a new object is created, and is used to properly initialise all member variables of an object. The destructor, instead, is the special method that will be called when an object is about to be destroyed (either by exiting its scope or when the operator delete is called).

Resources

Books

Frameworks

GitHub repositories

Reddit Threads

Videos

Websites

YouTube playlists

PreviousC (programming language)NextCars

Last updated 1 year ago

Was this helpful?

- Changkun Ou ()

- Cross-Platform App Development Framework

- Jamie King

- abseil

- abseil

- Bo Qian

- The Cherno

- ChiliTomatoNoodle

- Bo Qian

- Bo Qian

Modern C++ Tutorial: C++ 11/14/17/20 On the Fly
GitHub
U++
fffaraz/awesome-cpp
filipdutescu/modern-cpp-template
LearnCPP
Modern C++ Programming Course (C++11/14/17/20/23)
mortennobel/cpp-cheatsheet
muqsitnawaz/modern-cpp-cheatsheet
rigtorp/awesome-modern-cpp
The C++ Build Process Explained
The comprehensive catalog of C++ books
Open source projects with examples of good modern C++
C++ Dynamic Linking vs Static Linking
Awesome Modern C++
C++ By Example
C++ Developer Guide
C++ Tips of the Week
Modern C++ Tutorial
Advanced C++
C++
C++ STD Gems
C++ Unit Test
Modern C++