About Pointers

Hi everyone,

sorry for the dummy question.
I just wonder why a char pointer pointer points a char ?
Namely, how does a char represent a memory location.

int pointer points memory location (ex : 123431)
I understand this hovewer , i couldnt understand char pointer.
It's exactly the same. It points to a memory location.
But How does a character point a memory location.
the char variable you declare must have a location in memory, right ?
so a char pointer will point to such locations.

int pointer points memory location (ex : 123431)

an PS : memory addresses should be 4bytes long (or 8bytes), and it's generally easier to express a memory address in hexadecimal:
p = 0x00ff6828

and i think it's rare to find a memory address that is an odd number, because CPUs feel comfortable when data are stored in sizes that are multiple of 2, so most of the time, addresses are multiple of 2.
It's not character.

Pointer is pointer. If it's char*, then it's simply information for you that it's pointer to some adress, and it points to enough space for char to be there.

Each variable has its own adress.
So basically, with pointer (let's say, char* p) , we have 3 things:
*p = it's the variable that p is pointing to.
p = it's adress of variable that p is pointing to
&p = it's the adress of our pointer.

So, we can have:

char c = 'c';
char* pointC = &c; // now pointC points to c. 

I recommend you reading tutorial on pointers from this site.
Last edited on
char *p1; //pointer to char, holds address of char
int  *p2; //pointer to int,  holds address of int
T    *p3; //pointer to T,    holds address of T 
Topic archived. No new replies allowed.