This blog is about providing theory as well as simple executable codes of different programming languages such as java, C, C++, and web programming, etc. This blog will be helpful to the IT students to learn about programming.

Tuesday, February 21, 2023

Write short notes on 1. abstract class 2. arrays in C++ 3. new and delete operator

 1. Abstract Class:

An abstract class is a class that cannot be instantiated and must be inherited by a subclass. The abstract class is a blueprint or a template for creating other classes. The abstract class provides a set of methods or functions that must be implemented in the subclass. It contains one or more pure virtual functions, which are declared but not defined. The pure virtual function is declared using the "virtual" keyword, followed by "= 0" to indicate that it has no implementation.

2. Arrays in C++:

An array is a collection of similar data items stored in contiguous memory locations. Each element in an array is identified by its index or subscript. In C++, arrays can be of a fixed or dynamic size. The size of a fixed-size array is determined at compile time and cannot be changed during runtime. A dynamic array is created using the "new" operator and can be resized during runtime using the "realloc" function.


3. New and Delete Operators:

The "new" operator is used to allocate memory dynamically during runtime. The "new" operator returns a pointer to the allocated memory. The syntax of the "new" operator is as follows:

ptr = new data_type;

The "delete" operator is used to deallocate memory that was allocated using the "new" operator. The syntax of the "delete" operator is as follows:

delete ptr;

The "delete" operator frees the memory that was allocated using the "new" operator. It is important to use the "delete" operator to free the memory, as failure to do so can result in memory leaks.




No comments:

Post a Comment

If you have any doubts, please let me know

Slider Widget