1. Write the shorts notes on Garbage collection.
Ans. Garbage collection in C++ isn't native to the language; it relies on manual memory management using constructs like new
and delete
. However, some third-party libraries or smart pointers like std::shared_ptr
and std::unique_ptr
offer automated memory management. C++11 introduced smart pointers, reducing manual memory handling but lacking the automatic garbage collection found in languages like Java or Python.
2. What is multiple heritance?
Ans. Multiple inheritance in C++ enables a class to inherit attributes and behaviors from more than one base class. It allows a derived class to access features from multiple parent classes, fostering complex class hierarchies but potentially causing issues like the diamond problem due to ambiguous member access.
3. What do you mean by operator overloading ?
Ans. Operator overloading in C++ allows defining custom behaviors for operators like +, -, *, etc., for user-defined types. It enables classes to redefine how operators work with their objects, enabling intuitive and meaningful operations beyond their standard functionality.
4. What is the class and objects?
Ans. class. In C++, a class serves as a blueprint defining properties and behaviors shared by objects. It encapsulates data (attributes) and functions (methods), allowing the creation of multiple instances with similar characteristics and actions.
Objects.In C++, objects are instances of classes. They represent real-world entities, storing data and behaviors defined within their class blueprint, allowing interaction and manipulation through defined methods.
5. Explain Constructor and Destructor.
Ans. Constructors in C++ initialize objects of a class, setting their initial state and allocating resources. Destructors, prefixed with a tilde (~), clean up allocated resources when an object goes out of scope, ensuring proper memory management and releasing held resources like memory or file handles.
6.What is Function overloading?
Ans. Function overloading in C++ permits multiple functions with the same name but different parameters or types within a class. It enables using the same function name for diverse operations, simplifying code and improving readability.
7.What is the access specifier?
Ans. Access specifiers in C++—public, private, and protected—control the accessibility of class members. Public allows unrestricted access, private limits access to within the class, and protected allows access within the class and its derived classes, managing data encapsulation and abstraction.
8.what is statics data class?
Ans. Static data members in C++ belong to the class rather than individual objects. They're shared among all instances of the class, maintaining a single copy of the data. They're accessed using the class name, not object instances.
Examples.class Example { public: static int count; // Declaration of static member Example() { count++; // Increment count for each object created } }; int Example::count = 0; // Initialization of static member int main() { Example obj1, obj2, obj3; std::cout << "Total objects created: " << Example::count << std::endl; // Accessing static member using class name return 0; }
9.what is heap short ?
Ans. The heap in C++ is a region of memory where dynamic memory allocation occurs using functions like new
and delete
. It allows for flexible memory management, unlike the stack, enabling dynamic data storage.
10. what is the concept of marge sorting?.
Ans. Merge sort in C++ is a divide-and-conquer algorithm. It divides the array into smaller parts, sorts them individually, then merges them back together. It repeatedly divides the array until single elements remain, then merges them, maintaining a sorted order, achieving efficient O(n log n) performance.
Comments
Post a Comment