Dereferencing within a buffer
Posted
by kaykun
on Stack Overflow
See other posts from Stack Overflow
or by kaykun
Published on 2010-06-06T04:37:41Z
Indexed on
2010/06/06
4:42 UTC
Read the original article
Hit count: 362
Filed under:
c
Let's say I had a char pointer pointing to a buffer that contained these values (in hex):
12 34 56 78 00 00 80 00
I want to modify the last two bytes to a short
value of 42. So I would think I would have to do something like this:
(short)*(pointer+6)=42;
The compiler doesn't complain but it does not do what I'm expecting it to do. Can someone tell me the correct way to assign the value?
© Stack Overflow or respective owner