ObjectiveMcq
Print Protected
This page is protected for print. Use the website to view the content.
What will be the output of the following C++ code
#include <iostream>
using namespace std;
class A{
public:
int a;
A(){
cout<<"Constructor called";
}
};
int main(int argc, char const *argv[])
{
A a1 = (A)malloc(sizeof(A));
return}
Correct Answer: C — Nothing printed
Unlike new malloc never calls the constructor of a class hence when we are assigning memory to an object of class A using malloc constructor is not called hence nothing is printed.