Sobes.tech
Junior — Middle

Can you explain what the C++ programming language is and what its main features are?

sobes.tech AI

Answer from AI

C++ is a general-purpose programming language that supports both procedural and object-oriented programming. It extends the C language by adding features for working with classes, inheritance, polymorphism, and templates.

Main features of C++:

  • Object-oriented: support for classes, encapsulation, inheritance, and polymorphism.
  • Low-level control: ability to work directly with memory through pointers.
  • Templates (generics): allow writing generic code that works with different data types.
  • Standard library (STL): contains containers, algorithms, and iterators for convenient data handling.
  • Multiple inheritance: a class can inherit behavior from multiple base classes.

Example of a simple class in C++:

#include <iostream>

class Animal {
public:
    void speak() {
        std::cout << "Animal sound" << std::endl;
    }
};

class Dog : public Animal {
public:
    void speak() {
        std::cout << "Woof!" << std::endl;
    }
};

int main() {
    Dog dog;
    dog.speak(); // Outputs: Woof!
    return 0;
}