Let's say I have some pointers called:
char * pChar;
int * pInt;
I know they both simply hold memory addresses that point to some other location, and that the types declare how big the memory location is pointed to by the particular pointer. So for example, a char might be the size of a byte on a system, while an int may be 4 bytes.. So when I do:
pChar++; // I am actually incrementing the address pointed to by pChar by 1 byte;
pInt++; // I am actually incrementing the address pointed to by pInt by 4 bytes;
But what if I do this:
pChar+2; // increment the address pointed to by pChar by 2 bytes?
pInt+2; // increment the address pointed to by pInt by 2 bytes? what happens to the other two bytes?
Thanks.. Would appreciate any clarification here.. Is the pointer type simply for the ++ operation?
EDIT: So avp answered my question fittingly, but I have a follow up question, what happens when I do:
memcpy(pChar,pInt,2);
Will it copy 2 bytes? or 4 bytes? Will I have an access violation?
EDIT: THe answer, according to Ryan Fox, is 2 bytes, because they are typecasted to a (void*). Thanks! CLOSED!
EDIT: Just so that future searchers may find this.. Another piece of info I discovered..
memcpy(pChar+5,pInt+5,2);
doesnt copy 2 bytes of the memory block pointed to by pInt+5bytelocations,to pChar+5bytelocations.. what happens is that 2 bytes are copied to pChar+5bytelocations from pInt(4*5)bytelocations.. no wonder I got access violations, I was trying to read off somewhere I wasn't supposed to be reading.. :)