我该如何做这样的事情?
void *memory = malloc(1000); //allocate a pool of memory
*(memory+10) = 1; //set an integer value at byte 10
int i = *(memory+10); //read an integer value from the 10th byte
最佳答案
简单示例:将内存视为无符号字符数组
void *memory = malloc(1000); //allocate a pool of memory
uint8_t *ptr = memory+10;
*ptr = 1 //set an integer value at byte 10
uint8_t i = *ptr; //read an integer value from the 10th byte
您也可以使用整数,但是您必须注意一次设置的字节数。
关于c - 如何从 C 中的 "raw"内存中读取/写入类型值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11490984/