Ahmad

Ahmad

#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.…

#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 sounds simple, but it is one of the most important ideas in C++. Where you declare a variable determines where it can be used,…

#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. Additionally, if it was legal it opens a can of worms:…