Search



Thursday, 20 August 2015

Pointers Theory

A variable that stores the memory location (address) of another variable, i.e direct address of the memory location are pointers.
Basically, Pointers are the control power of manipulating address of any variable.

Pointer Syntax :
Represented by *p (Variable with * not only shows but also known by compiler).

Pointer Arithmetic :


  • When a pointer variable points to an array element, there is a notion of adding or subtracting an integer to/from the pointer.
  •  If two pointers point to elements of a same array, then there are notions of subtraction and comparisons between the two pointers.
  • Array names come with valid spaces where they “point” to.  And you cannot “point” the names to other places.
  • Pointers do not point to valid space when they are created.  You have to point them to some valid space (initialization).


Now,Major difference between Array and Pointers:
PointerArray
1. A pointer is a place in memory that keeps address of another place inside 
 1. An array is a single, pre    allocated chunk of contiguous  elements (all of the same  type), fixed in size and  location.
2. Pointer can’t be initialized at definition.

 2. Array can be initialized at  definition. Example
 int num[] = { 2, 4, 5}
3. Pointer is dynamic in nature. The memory allocation can be resized or freed later.
 3. They are static in nature.    Once memory is allocated , it  cannot be resized or freed  dynamically.
4. The assembly code of Pointer is different than Array
 4. The assembly code of          Array is different than Pointer.

No comments:

Post a Comment

Guys if you think something is wrong or should be edit than please do comment.