29-09-2012, 01:13 PM
POINTERS AND DYNAMIC MEMORY MANAGEMENT
Pointers.pptx (Size: 183.21 KB / Downloads: 22)
INTRODUCTION
Pointers are one of the most important features of C++ language. Pointers need very careful handling. There are many reasons for using pointers.
A pointer allows a function or a program to access a variable outside the preview of function or program.
Use of pointer increases makes the program execution faster.
Using pointers, arrays and structures can be handled in more efficient way.
To communicate with operating system about memory.
ACCESSING ADDRESS OF A VARIABLE
The actual address of a variable is system dependent. During compilation and linking, addresses are assumed to be relative to some base address, usually 0. When the operating system loads the program in a free block, all the address are transformed with relative to address of the first memory location of the free block.
Consider the following statement :
Possible problems with the use of pointers
The most common problem with pointers is that the programmer fails to initialize a pointer with a valid address. Such an initialized pointer, referred to as dangling/wild pointer, can end up pointing anywhere in memory that may include the program code itself or to the code of the operating system. When the system stop responding, we say the system has hanged up and the only option left is to reboot the system. Therefore, care must be taken to initialize pointers with valid address.
Pointers.pptx (Size: 183.21 KB / Downloads: 22)
INTRODUCTION
Pointers are one of the most important features of C++ language. Pointers need very careful handling. There are many reasons for using pointers.
A pointer allows a function or a program to access a variable outside the preview of function or program.
Use of pointer increases makes the program execution faster.
Using pointers, arrays and structures can be handled in more efficient way.
To communicate with operating system about memory.
ACCESSING ADDRESS OF A VARIABLE
The actual address of a variable is system dependent. During compilation and linking, addresses are assumed to be relative to some base address, usually 0. When the operating system loads the program in a free block, all the address are transformed with relative to address of the first memory location of the free block.
Consider the following statement :
Possible problems with the use of pointers
The most common problem with pointers is that the programmer fails to initialize a pointer with a valid address. Such an initialized pointer, referred to as dangling/wild pointer, can end up pointing anywhere in memory that may include the program code itself or to the code of the operating system. When the system stop responding, we say the system has hanged up and the only option left is to reboot the system. Therefore, care must be taken to initialize pointers with valid address.