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

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -