C & C++ Interview Questions – Excellence Technology C & C++ Interview Questions – Excellence Technology

C & C++
Interview Questions

C & C++ Interview Questions

C is a procedural programming language, while C++ is a combination of procedural and object-oriented programming languages. C++ also includes additional features like classes, inheritance, and polymorphism.

Both malloc() and calloc() are used for dynamic memory allocation. malloc() allocates a block of memory but does not initialize it, while calloc() allocates a block of memory and initializes it with zero.

const is used to declare variables as constants, and their values cannot be changed after initialization. volatile is used to indicate that a variable may be changed by external sources, and the compiler should not optimize or reorder access to it.

A pointer is a variable that stores the memory address of another variable. An array is a collection of elements of the same type stored in contiguous memory locations. While an array name represents the address of the first element, a pointer can point to any memory location.

C++ is an extension of C with additional features, including classes, objects, inheritance, polymorphism, and encapsulation. C++ is often considered an object-oriented programming (OOP) language, while C is a procedural programming language.

Function overloading allows the definition of multiple functions with the same name but different parameter lists. The compiler selects the appropriate function based on the number and types of arguments passed to it.

A class is a blueprint or template for creating objects. It defines the properties (attributes) and behaviors (methods) that the objects of the class will have. An object is an instance of a class, representing a specific entity with its own set of attributes and behaviors.

  • Inheritance: It allows a class to inherit properties and methods from another class, promoting code reusability.
  • Polymorphism: It enables objects of different classes to be treated as objects of a common base class, providing a way to use a single interface for different types of objects.
  • Encapsulation: It involves bundling the data (attributes) and the methods that operate on the data into a single unit or class.

new is an operator in C++ used for dynamic memory allocation and object creation, while malloc() is a function in C used for dynamic memory allocation. The new operator calls the constructor, and the memory allocated by new must be deallocated using delete. malloc() and free() are used in C and do not call constructors.

Vectors are dynamic arrays in C++ STL that provide dynamic size, efficient random access, and automatic resizing. They are part of the Standard Template Library (STL) and offer functions for various operations such as adding, removing, and accessing elements.

Both map and unordered_map are associative containers in C++. The main difference is that map is ordered, maintaining the order of key-value pairs based on the key's natural ordering, while unordered_map is unordered and provides faster average lookup times.

The delete operator is used to deallocate memory that was previously allocated using the new operator. It is essential to prevent memory leaks and ensure that dynamically allocated memory is released when it is no longer needed.

Pointers and references both provide a way to work with memory addresses, but they have key differences. Pointers can be reassigned and can be null, while references cannot be reassigned and must be initialized when declared. Additionally, pointers can point to different memory locations, while references are tied to the same memory location throughout their lifetime.

Exceptions in C++ are handled using try, catch, and throw blocks. Code that may throw an exception is enclosed in a try block, and exceptions are caught and handled in catch blocks.

Exceptions in C++ are handled using try, catch, and throw blocks. Code that may throw an exception is enclosed in a try block, and exceptions are caught and handled in catch blocks.

Still have questions? Contact us We’d be Happy to help





    CAN'T FIND ANSWER? ASK US DIRECTLY!