Malloc | SoloLearn: Learn to code for FREE!



What the following code does? X=(int*)Malloc(sizeof(int)) * 6; In c programming language...


8/13/2019 12:15:05 PM

Syed Waseem

4 Answers

New Answer


Syed Waseem When allocating memory dynamically in the heap malloc function is used, the function malloc retuns a handle which needs to be stored in a pointer to appropiate datatype where X is an integer pointer you can do like this way too int* ptr = (int*) malloc(sizeof(int) * 6); X = (int*) malloc(6 * sizeof(int)); // 6 ints. Memory is allocated at the heap (a total of 24 bytes, assuming sizeof(int) is 4 bytes when your task is completed then free the memory from being safe with memory leakage. free(X)


Yes 6 integers with memory allocation of 24 bytes as pointer has defined data type as integer


Thanks, For Your help...🤝


So, it returns total 6 int pointer to x...