Part 20 – Character Variables
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 character variables. Unlike the strings we have dealt with thus far, a character only takes up one byte of data.
Keep in mind, when we deal with any character data, we deal with literally two hex digits which are the ASCII code that represents an actual character that we see on our respective terminals.
Remember that each hex digit is 4 bits in length. Therefore two hex digits are 8 bits in length or a byte long.
To recap, each character translates down to an ASCII code in hex which the processor understands. The value of n is 0x6e hex or 110 decimal. You can review any ASCII table to see where we derived this value. This will come in handy in the next lesson.
We start with our third program in C++ which is our “Character Variable” program. Let’s dive in and break each line down step-by-step and see how this language works. We will call this example3.cpp and save it to our device.
#include <iostream>
int main(void) {
char yes_no = ‘n’;
std::cout << yes_no << std::endl;
return 0;
}
To compile this we simply type:
g++ example3.cpp -o example3
We simply then type:
./example3
SUCCESS! We see “n” printed to the standard output or terminal!
Let’s break it down:
We utilize the char keyword to indicate a character variable to which we assign it the value of n.
We then utilize the cout function to print it to the standard output or terminal and add a new line with the endl function.
That’s it! Very simple.
Next week we will dive into Debugging Character Variables.