Friday, 17 April 2015

POINTERS IN C++


Introduction

C++ takes the middle ground between languages, which support dynamic memory allocation, and languages in which all variables are dynamically allocated.

C++ supports creation of objects with scoped lifetimes and with arbitrary lifetimes. Stack-based objects are managed b the compiler implicitly, whereas heapbased objects are managed by the programmers explicitly.

A class can be instantiated at runtime and objects created by such instantiation are called Dynamic Objects. The lifetime of dynamic objects in C++ is managed explicitly by the program. The program must be guarantee that each dynamic object is deleted when it is no longer needed, and certainly before it becomes garbage. The lifetime of an object in

C++ is interval of time exists by occupying memory. Creation and deletion of objects as and when required, offers a great degree of flexibility in programming.

Objects with scoped lifetimes are created in the stack memory. Stack memory is a store house which holds local variables or objects, and whenever they go out of scope, the memory allocated for them in the stack is released automatically.

Objects with arbitrary lifetimes are created in the heap memory. These dynamic objects can be created or destroyed as and when required, explicitly by the programmer. The operators new and delete used with standard data type variable’s management can also be used for creating or destroying objects at runtime respectively.

No comments:

Post a Comment