c - How to store an integer in a location pointed to by a char* -
this might basic question asked not quite sure if answer here casting int pointer char ptr , vice versa applicable in case. have follows:
void* head = sbrk(1024); //allocate 1024 bytes in heap *((int*)(head+size)) = value; //value , size int valoues between 1 , 1023
i know if arbitrary value of size above not work restrictions on value of size? have divisible 4?
use memcpy()
:
memcpy((char*)head + size, &value, sizeof(value));
Comments
Post a Comment