I have a few questions about pointers.
I have the following struct
struct buffer {
char *ptr;
char data[DATA_SIZE];
};
and I have the following code
printk("ptrs and what not: buf=%p, b-ptr=%p, b-data=%p, INIT_LOC=%lu\n", buf, buf->ptr, buf->data, INIT_LOC);
if (buf)
buf->ptr = buf->data + INIT_LOC;
printk("ptrs and what not: buf=%p, b-ptr=%p, b-data=%p, INIT_LOC=%lu\n", buf, buf->ptr, buf->data, INIT_LOC);
The output is the following:
ptrs and what not: buf=ffff880091ae2000, b-ptr= (null), b-data=ffff880091ae2008, INIT_LOC=10
ptrs and what not: buf=ffff880091ae2000, b-ptr=ffff880091ae2012, b-data=ffff880091ae2008, INIT_LOC=10
questions
1) when adding a number, lets say 2 to a ptr with an address lets say 10001
is the value 10003, or 10001 + 2 * sizeof(X), where x is the type of the ptr.
2) if ptr=10001 is an array of chars in memory, the first character in that array is at location 10001, is the second character at location 10002 or 10009? or what would it be?
3) going to the printout shown above the buf->data has address 2008, i am not sure how adding 10 to it makes it point to 2012.
Thanks in advance.
10001 + 2 * sizeof(X)10002