C Programming - Complicated Declarations - Discussion

Discussion Forum : Complicated Declarations - True / False Questions (Q.No. 2)
2.
It is not necessary to typecast the address returned by malloc().
True
False
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
8 comments Page 1 of 1.

Ashwini patil said:   10 years ago
Type casting is a way to convert a variable from one data type to another data type. For example, if you want to store a long value into a simple integer then you can type cast long to int.

Suresh Dave said:   1 decade ago
Actually its true! Its not necessary in C but in C++ its necessary. If you want your program to be generic (portable) then better you typecast it properly.
(1)

Gangadhar said:   1 decade ago
malloc returns generic pointer(void *). So no need to typecast at all. It's not mandatory and there is no wrong if we typecast.

Satya said:   1 decade ago
Explain malloc and calloc functions in c.

Razi said:   1 decade ago
malloc return a generic type pointer.Because generic pointer is of type void (void *p,p is generic pointer).Void pointer can hold any type of data so it is needed to typecast it.

Jan said:   1 decade ago
In pure C, it is not necessary to typecast malloc. However, you will have to typecast it if you want to access that value pointed to by the pointer. There will be no compiler error anyhow.

Suriya rathi said:   1 decade ago
Typecast means to convert from one type to other, eg, suppose we are storing an integer type in a string, we need to explicitly convert the int type to string.

Vikas said:   1 decade ago
What's the meaning of typecast?

Post your comments here:

Your comments will be displayed after verification.