Created
November 21, 2018 13:55
-
-
Save codenulls/ea55f43547ded5c7055f7048373efef0 to your computer and use it in GitHub Desktop.
Shows how an `int` type variable looks like in memory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <cstdio> | |
#include <cstdint> | |
int main() | |
{ | |
int amount = 9000; | |
std::printf("Address of amount: %p\nValue of amount in decimal: %d\nValue of amount in hexadecimal: %#.8x\n", &amount, amount, amount); | |
std::uint8_t* amountAddress = reinterpret_cast<std::uint8_t*> (&amount); | |
for (int i = 0; i < sizeof(int); i++) | |
{ | |
std::printf("Address of byte %d : %p | value: %#.2x\n", i+1, amountAddress, *(amountAddress + i)); | |
} | |
getchar(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment