Alex's Slip-box

These are my org-mode notes in sort of Zettelkasten style

Cpp reference

:ID: 10aae082-3051-421d-8412-031e2042126d

# Constants

# const

# constexpr

  • Optimization technique.
  • Use for compile time computation when function is called with constants
  • Function is called a runtime with invoked with non-constants

# consteval

  • c++20
  • Same as constexpr but required to be evaluated at compile time.

# Types

# Char

  • Use std::string over char lists (C strings). Safer to avoid buffer overflows.
  • You can turn a std::string (C++ string) into a C string with myCppString.c_str()

# Auto

Have the compiler infer the type

# typedef

Used to define a type

# Arrays

# Static

# Dynamic

  • Use std:vector to declare a dynamic array and push_back() to add more elements and the array will be resized as needed.

    std::vector<int> someList(1); // init array with size of 1
    someList[0] = 1;
    someList.push_back(2); // Use push_back to add more items and resize array at runtime

# Compiling

Basically each .cpp file can be compiled separately to create .o files which can be linked together to create one executable.

  • g++ -c file1.cpp: creates file1.o
  • g++ -c file2.cpp: creates file2.o
  • g++ my_executable file1.o file2.o: Links the files and creates the executable.

# Makefile

# Cmake

# Using third party libraries

# Package managers


# Spacemacs

# Online Repl

Search Results