#034 – The conditional operator is CHEESE

Conditional operator allows us to do this: and this: Introduction The conditional operator (?:) is also called the arithmetic if operator. It’s a ternary operator, meaning it requires 3 operands. Historically, it’s been C++’s only ternary operator. It’s concise way…

#031 – std::string_view: A Lightweight String Reference

Consider this program Here’s what happens This is additional overhead for simply getting a string. This is inefficient. Fortunately, we can do better. Since we don’t modify the string, this is a good justification to use std::string_view. Introducing std::string_view (C++17)…

#030 – Printing integers in binary

Consider the following: Hey! What happened? We assigned binary values to the variable however std::cout printed their decimal representation. C++ allows us to initialize a variable with any numbering system All of these values are equivalent. However, the variable doesn’t…

#029 – Using literal suffixes

Introduction Consider the following, Woah! Even though we didn’t specify the type of the variable, the compiler was able to deduce it. When auto is used, the compiler deduces the variable’s type from the initializer. Since literals already have types,…

#027 – Floats or doubles?

Introduction Integers are great and all but if you want to store numbers with a fractional component. This is often what you see in the real world. Temperature, distance, currency all contain a fractional component. In these applications, you must…

#024 – The dangers of using unsigned ints

Unsigned int‘s are strictly positive. It gets double the positive range than its signed counterpart. It seems like a free upgrade. However, unsigned integers introduce a class of bugs that are easy to write, difficult to detect, and silently destructive.…