How does giving numbers to addresses work?
Hey,
I wrote a quick program that asks for a number, saves it, and prints out the address where it saved it:
#include <iostream>
using namespace std;
int main() {
int x;
cout << "Input an integer:" << endl;
cin >> x;
cout << "I saved your number at the address "<< &x << "." << endl;
}
After running, the output was 0x7fff0cc4fb7c. I assume (and please correct me if that's wrong) that this address refers to a specific byte in my RAM, namely the first of the four bytes that represent x.
But: 0x7fff0cc4fb7c equals 140733407624060 in decimal, or about 1.4 * 10^(14). 10^(14) bytes means 100 TB (not TiB). My machine has 4 GB RAM. How can the address have a value in the 10^(14) range when there are only about 4 * 10^9 bytes?
Edit: Probably a bad title, but I hope my intention got clearer in the text.
Posted Apr 13, 2013, 10:00 PM UTC · edited
69