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

Explain what is the heap?

618


I completed my B.tech (IT). Actually I want to develop virtual object that which will change software technology in the future. To develop virtual object what course I have to take. can I any professor to help me.

1735


What are static variables in c?

626


What is assert and when would I use it?

573


Why static is used in c?

616






write a progrmm in c language take user interface generate table using for loop?

1571


What is the use of typedef in c?

577


What is size of union in c?

578


What is the difference between functions abs() and fabs()?

643


What are examples of structures?

590


What is sizeof in c?

566


Can static variables be declared in a header file?

612


Explain the difference between malloc() and calloc() function?

596


Why do we use null pointer?

601


Is calloc better than malloc?

570