I have a pointer that points to first byte of a shared memory which is 66 bytes long. I want to create another pointer that points to a certain byte in shared memory (I’m saying certain byte because I want to get this info from user as integer like:”which byte do you want to reach?”). Is there a way of reaching a certain byte via shared memory’s pointer?
Share
The shared memory part is irrelevant: what you have is a pointer and you want to increment n bytes:
Or in your case, more safely:
You need to cast to
char*because pointer arithmetic dictates thatT* + nincrementssizeof(T); we want to increment by bytes, andcharis that type (with a size that’s always 1).(Aliasing a value through a
char*is okay.)