MCQs > IT & Programming > C++ > Consider the following code: class Animal { private: int weight; public: Animal() { } virtual void Speak() { cout << 'Animal speaking'; } }; class Snake : public Animal { private: int length; public: Snake() { } void Speak() { cout << 'Snake speaking\r\n'; } }; int main() { Animal *array = new Snake[10]; for (int index= 0; index < 10; index++) { array->Speak(); array++; } return 0; } What happens when the above code is compiled and executed?

C++ MCQs

Consider the following code:
class Animal
{
private:
int weight;
public:
Animal()
{
}
virtual void Speak()
{
cout << "Animal speaking";
}
};
class Snake : public Animal
{
private:
int length;
public:
Snake()
{
}
void Speak()
{
cout << "Snake speaking\r\n";
}
};
int main()
{
Animal *array = new Snake[10];
for (int index= 0; index < 10; index++)
{
array->Speak();
array++;
}
return 0;
}
What happens when the above code is compiled and executed?

Answer

Correct Answer: The code will crash at runtime

Explanation:

Note: This Question is unanswered, help us to find answer for this one

C++ Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

search

C++ Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it