Wait, pointers are pointers to objects: integers, chars, floats, structures, etc.
OK got that, is every variable then in C an array or do they have to be explicitly be declared as an array before I can access different locations of that array.
By this I mean let's say we have an int var = 0x1234,
not explicitly declared as an array, can I still access any of the 4 bytes that are used for the int?
Similar to assembler where we can load a 32 bit value in EAX but then manipulate say the bottom 16 bits with AX or AH, AL for 8 bits?
But an array name is the pointer to its first element. So it's true the way round
As in ThisArray[0] ?
Now we touch one of the obscure features of C: an array and a pointer of the same type share the same properties and methods, even if the assembly code to access data is completely different! Another difference is that you can get the address of a pointer, which is a variable holding the address of another variable, but you cannot get the address of an array.
So a pointer at say address 1000 contains a value of 5000, this value is then the address of the variable in the array ?
Will also try the code you posted.
What I found that has also helped to clear a bit of my confusion is this code snippet:
struct {
char a;
char b;
char c;
char d;
} mystruct;
mystruct.a = 'r';
mystruct.b = 's';
mystruct.c = 't';
mystruct.d = 'u';
char* my_pointer;
my_pointer = &mystruct.b;
printf("Start: my_pointer = %c\n", *my_pointer);
my_pointer++;
printf("After: my_pointer = %c\n", *my_pointer);
my_pointer = &mystruct.a;
printf("Then: my_pointer = %c\n", *my_pointer);
my_pointer = my_pointer + 3;
printf("End: my_pointer = %c\n", *my_pointer);
It's about half way down the page here:
http://stackoverflow.com/questions/5727/what-are-the-barriers-to-understanding-pointers-and-what-can-be-done-to-overcomeI understand the concept of addresses and memory, it's just getting to grips with the C syntax.
Thank you very much for your help.