Skip to content

Instantly share code, notes, and snippets.

@codenulls
Created November 21, 2018 13:55
Show Gist options
  • Save codenulls/ea55f43547ded5c7055f7048373efef0 to your computer and use it in GitHub Desktop.
Save codenulls/ea55f43547ded5c7055f7048373efef0 to your computer and use it in GitHub Desktop.
Shows how an `int` type variable looks like in memory.
#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