What's wrong with "char *p = malloc(10);" ?

Answer Posted / guest

malloc returns a void pointer. It needs to be cast to char*
before allocating it to char* variable.
char *p = (char *)malloc(10); should do fine.

Is This Answer Correct ?    26 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

difference between Low, Middle, High Level languages in c ?

1845


where are auto variables stored? What are the characteristics of an auto variable?

826


What is boolean in c?

815


while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above

975


Explain what are the __date__ and __time__ preprocessor commands?

850


What does nil mean in c?

892


What is the hardest programming language?

896


What does the error 'Null Pointer Assignment' mean and what causes this error?

963


What does %2f mean in c?

957


what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?

1652


#include int main(){ int i=10; int *ptr=&i; *ptr=(int *)20; printf("%d",i); return 0; } Output: 20 can anyone explain how came the output is 20

1494


Is swift based on c?

845


How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?

16020


What is a global variable in c?

768


What math functions are available for integers? For floating point?

850