Junior — Middle
What distinguishes the C++ language from the C language in terms of syntax and capabilities?
sobes.tech AI
Answer from AI
C++ extends the capabilities of the C language by adding object-oriented programming, templates, exceptions, and a richer standard library. In terms of syntax:
- C++ introduced classes, inheritance, and polymorphism.
- Namespaces were added for code organization.
- Support for function and operator overloading.
- Introduction of templates for generic programming.
Example of a class in C++:
class Animal {
public:
void speak() {
std::cout << "Animal sound" << std::endl;
}
};
In C, such syntax does not exist; it only supports procedural style.