For example:
char mem[100000];
int reg[8];
mem[36] = 'p'; // add char p to our 36th index of our char array
reg[3] = (int)mem[36]; // store value of mem[36] into reg[3]
Now I want to print the char value at index 3 of that int array.
So far my thought process has lead me to code such as this:
char *c = (char*)reg[3];
cout << *c << endl;
But I am still getting weird values and characters when trying to print it out.
From my understanding, an integer is equal to 4 characters. Since a character is technically a byte and an integer is 4 bytes.
So I am storing a character into my integer array as 4 bytes, but when I pull it out, there is garbage data since the character I inserted is only one byte compared to the index being 4 bytes in size.
cout << reg[3] << endl;?