Suppose I have:
unsafe {
byte* start = GetStartLocation();
int something = start[4];
}
What is 'something'? The value of the memory address 4 bytes down from start?
Suppose I have:
unsafe {
byte* start = GetStartLocation();
int something = start[4];
}
What is 'something'? The value of the memory address 4 bytes down from start?
The value of something is the byte value of offset 4 from start widened to an int type.
It's equivalent to the following code
byte temp = start[4];
int something = temp;
Say start
points to memory location 0x12345678, and memory looks like this:
0x12345678 0x12
0x12345679 0x34
0x1234567a 0x56
0x1234567b 0x78
0x1234567c 0x9a
0x1234567d 0xbc
then something
equals 0x9a
.
The fact that something
has type int
doesn't matter to how start[4]
is interpreted - it gets the byte
value of the byte 4 locations away from start
.