0

Malloc

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

13th Aug 2019, 12:15 PM
Syed Waseem
Syed Waseem - avatar
4 Respuestas
+ 11
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)
13th Aug 2019, 12:27 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 10
Yes 6 integers with memory allocation of 24 bytes as pointer has defined data type as integer
13th Aug 2019, 12:30 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
Thanks, For Your help...🤝
13th Aug 2019, 12:31 PM
Syed Waseem
Syed Waseem - avatar
0
So, it returns total 6 int pointer to x...
13th Aug 2019, 12:29 PM
Syed Waseem
Syed Waseem - avatar