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

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -

r - Update two sets of radiobuttons reactively - shiny -