Ahmad

Ahmad

#023 – How big is an int?

In #021 – Thinking in memory. What a variable ACTUALLY is, we established that variables are simply representations of values that are stored in memory locations. When you initialize a variable int y {11};, the compiler reserves a portion of…

#022 – Using void as a function parameter

void is a special type. It means no type! We are accustomed to functions returning void. However, a function parameter can also be void. This means the function accepts zero parameters. Why is this possible? This feature is inherited from…

#019 – The std namespace

Introduction The entire C++ standard library lives inside a single namespace called std, which acts as one large container holding all of its functionality. The standard library is the result of decades of work by some of the best engineers…

#018 – Two reasons to use forward declarations

Consider the following: In main(), we call the function before its implementation. This is possible since we included a forward declaration before the function call. This tells the compiler: Hey, just letting you know this function exists. However, I’ll implement…

#017 – Crash Course on Local Variables

Introduction A local variable in C++ is any variable defined within a function (or block). This definition is type-agnostic—it does not matter whether the variable is a fundamental type (int, double), a standard library type (std::string, std::unique_ptr), or a user-defined…

#016 – Using function calls as arguments

Consider this program The return value of GetRadius() is stored in a variable and passed into CalculateArea(). x only exists act as the interface between the two functions. We can do better. Doing Better We merge these two instructions in…

#015 – C++ does not support nested functions

Consider the following: According to the rules of C++, nested functions are illegal. Functions must be implemented in the global namespace. Then they can be called in other functions. Why is this the case? This behaviour was inherited from C.…

#014 – Chaining operators

Consider the following: This statement contains multiple << operators that are chained in a single instruction. The insertion operator (<<) operators on a C-style string literal, an escape sequence, a class object and a function. The answer comes down to…