How is a pointer variable for integer stored?

4

When we declare:

int* x;

How does the compiler compile this and how does the computer (would it be better to say operating system because it is the one that manages the memory) does this?

I mean, S.O. reserves a space in memory to store a memory address of type int and names it x . But how does he do it? Do you have a flag in your own memory that says you only accept integers? If it were an address for char what would it change? And how does he know that her name is x ? Would it be another flag?

Thank you.

    
asked by anonymous 23.09.2014 / 23:51

1 answer

2

This works by the symbol table. When you do

int *x;

The compiler goes in this table, allocates a space of 4 bytes in memory and associates the address of that location with the name x and type int * .

Then the table looks something like:

x    0xff843af int *

If it was a char , since it is nothing more than a number, your program interprets the value of the byte as char .

    
23.09.2014 / 23:54