Why use sizeof(int) in a malloc call? -
i new c++ , in mpi programming. have confused code block in c++
int count; count=4; local_array=(int*)malloc(count*sizeof(int)); why using sizeof(int) here in mpi programming?
i see you're trying allocate 4 ints here.
if @ malloc's signature, takes number of bytes first parameter. stated here, int data type takes 4 bytes.
therefore, if want 4 ints, have typed local_array=(int*)malloc(count*4);. not remembers int actualy takes 4 bytes. that's why use sizeof find out actual size of object or type.
Comments
Post a Comment