Junior — Middle
How do C and C++ programming languages differ in architecture and capabilities?
sobes.tech AI
Answer from AI
C is a procedural programming language focused on low-level memory and hardware resource management. It provides basic constructs for memory management, pointers, structures, and functions.
C++ extends C by adding support for object-oriented programming (OOP), including classes, inheritance, polymorphism, and encapsulation. Additionally, C++ supports templates (generics), exceptions, namespaces, and a richer standard library.
Architecturally, C++ maintains compatibility with C but allows for the creation of more complex and scalable programs through abstractions and extended language features.
Example of a class in C++:
class Rectangle {
public:
int width, height;
Rectangle(int w, int h) : width(w), height(h) {}
int area() { return width * height; }
};
int main() {
Rectangle rect(10, 5);
return rect.area();
}