x
and it has a value of 654
. Let's pretend that x
's memory address is "0x5FA70" (hexidecimal). Well, at the location "0x5FA70" in your computers memory is the number 654
. Still, don't see it? Okay, well let's just say for the sake of example that your computer's memory looks like this:memory address | value |
0x5FA62 | ... |
0x5FA66 | ... |
0x5FA70 | 654 |
0x5FA74 | ... |
0x5FA78 | ... |
654
. I put "..." in the other boxes because we don't know what's at those memory locations. On a nerdy note, I wrote the memory addresses in hexidecimal because its easier to represent them that way. Also, the addresses in this depiction increase in increments of 4. That is because the size (in bytes) of an integer is usually four (unless you're working with a crummy ol' 16-bit compiler). Actually you can try out the following program to see how big (in bytes) your typical integer is with your compiler:/* -example-[size of typical integer]-------------------------------- */
#include <iostream.h>
int main()
{
int x;
cout << "The size of integers on this compiler is " << sizeof(x)
<< " bytes." << endl;
return 0;
}
/* ------------------------------------------------------------------ */
After compiling and running the above program you'll know the default size of integers on your compiler. So for instance if it told you that they were only two bytes long then you could change my example listing of memory to increase by two rather than four. So instead of going "0x5FA62", "0x5FA66", ... it would go "0x5FA62", "0x5FA64", "0x5FA66" ...654
into x
it puts it at that memory address. The memory address is the place where that variable keeps its value. I suppose you might be able to say its like how everyone on the internet has an email address. Hmm, better yet. Since a memory address is a location ... if you were a variable then the place you were sitting/standing would be your memory address. And what you are is the value that is put there.&x
we would see "0x5FA70" rather than 654
. And how does this work, you ask?x
. Run this short program:
/* -example-[memory address of 'x']---------------------------------- */
#include <iostream.h>
int main()
{
int x = 654;
cout << "The value of 'x' is " << x << ", its memory address is "
<< &x << endl;
return 0;
}
/* ------------------------------------------------------------------ */
So by putting that ampersand in front of x
we're telling the compiler, "we don't care what the hell it has, we want to know where it is!" You'll get varying results from this program, for example when I compiled it through DJGPP I did get "0x5FA70".x
may very well be at that address. However, when you're program completes and exits (or crashes ), the address becomes available again. The next time you run your program x
could possibly be a memory address megabytes away!x
could be the car that gets you to see that nice person, "647". If you put an ampersand(&
) in front of x
you are looking for the house address and you could care less about who's inside.Page Content & Design ©1998 By Neil C. Obremski |
home |
prfce |
loop |
refs |
ptrs |
struct |
class |
array |
rsrc |
site |
indx |
Wed May 12 21:45:26 1999 |