Part 35 – SizeOf Operator

For a complete table of contents of all the lessons please click below as it will give you a brief of each lesson in addition to the topics it will cover. https://github.com/mytechnotalent/Reverse-Engineering-Tutorial

The next stage in our journey is that of the SizeOf operator.

Let’s examine our code.

  1. #include <iostream>
  2. int main(void) {
  3. int myNumber = 16;
  4. int myNumberSize = sizeof(myNumber);
  5. std::cout << myNumberSize << std::endl;
  6. return 0;
  7. }

Part 35 – SizeOf Operator - 图1

To compile this we simply type:

g++ example8.cpp -o example8

./example8

Part 35 – SizeOf Operator - 图2

We see 4 printed to the screen.

Let’s break it down:

We create a variable myNumber = 16 to which we create another variable myNumberSize which holds the value of the size of myNumber. We see that when we execute our code it shows 4 therefore we see that the SizeOf operator indicates an integer is 4 bytes wide.

Next week we will dive into Debugging SizeOf Operator.