C Programming - Memory Allocation - Discussion

Discussion Forum : Memory Allocation - True / False Questions (Q.No. 1)
1.
malloc() returns a float pointer if memory is allocated for storing float's and a double pointer if memory is allocated for storing double's.
True
False
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
16 comments Page 1 of 2.

Ashwin said:   1 decade ago
float *A;
A = (float*) malloc(1000*sizeof(float));

Because malloc is a generic memory allocation function, it is set up to return a generic pointer to a block of memory. Some compilers will complain if we attempt to assign a generic pointer to our pointer variable, so we have to use the type cast syntax (float*) to tell the compiler to reinterpret the generic pointer that malloc returns as a pointer to an array of floats.
(2)

Aniket said:   1 decade ago
malloc always return void pointer
prototype of malloc is (void*)malloc(size_t);
(1)

Viraj said:   1 decade ago
Void pointer is returned.

Raj said:   1 decade ago
malloc() and calloc() return void pointer for using a particular data type we made explicite type casting.

Mohini said:   1 decade ago
Thanks raj, viraj.

Panchanan rauta said:   1 decade ago
When a pointer success fully initialize it return void pointer.

Santosh said:   1 decade ago
Thanks raj.

Ashish kumar said:   1 decade ago
malloc always return void pointer it is wrong. malloc return void pointer when there is no typecasting. if there is typecasting then malloc return the pointer of typecast.
as
i=(void *)malloc(sizeof);//it return void pointer
i=(int*)malloc(sizeof(int));//it return integer pointer

Durgam_anil said:   1 decade ago
Prototype of malloc is (void*)malloc(size_t);

i=(void *)malloc(sizeof);//it return void pointer
i=(int*)malloc(sizeof(int));//it return integer pointer
i=(char*)malloc(sizeof(char));//it return char pointer

M.Salman said:   1 decade ago
malloc and calloc always returns no of bytes allocated which integer.


Post your comments here:

Your comments will be displayed after verification.