what is the behaviour of C and C++ compiler for the below
statements.
int *p;
p = malloc(100);

Is the behaviour same ? or different ?

Answer Posted / pramodsingh_45

In "C" the implicit typecasting will be done from void* to
int* but in C++ we need to do explicit typecasting.

so in C++
p = (int*)malloc(100);
but in C
p = malloc(100) will also work.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the most powerful coding language?

818


How a new element can be added or pushed in a stack?

783


Can I create my own functions in c++?

804


Write a single instruction that will store an EVEN random integer between 54 and 212 inclusive in the variable myran. (NOTE only generate EVEN random numbers)

1703


In what situations do you have to use initialization list rather than assignment in constructors?

828


What can I safely assume about the initial values of variables which are not explicitly initialized?

811


What programming language should I learn first?

794


an integer constant must have atleast one a) character b) digit c) decimal point

789


What is the meaning of string in c++?

785


What are the benefits of c++?

780


Difference between strdup and strcpy?

870


What is a memory leak c++?

769


What is the history of c++?

729


What happens if a pointer is deleted twice?

1015


Can comments be nested?

805