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 void pointer in c++ with example?

597


Explain deep copy and a shallow copy?

613


What are the two shift operators and what are their functions?

561


How can you quickly find the number of elements stored in a dynamic array? Why is it difficult to store linked list in an array?

561


Reverse the Linked List. Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL

338






List down the guideline that should be followed while using friend function.

649


What does iomanip mean in c++?

605


When should overload new operator on a global basis or a class basis?

615


Difference between strdup and strcpy?

650


Explain the isa and hasa class relationships. How would you implement each?

612


why is iostream::eof inside a loop condition considered wrong?

595


What is the oldest programming language?

570


What is expression parser in c++

1888


Are vectors faster than arrays?

569


What are the important differences between c++ and java?

604