Define pointers. Give advantages and disadvantages of pointers

Pointers

A pointer is a variable that contains the address in memory of another variable.

The two most important operators used with the pointer type are

  • & – The unary operator & which gives the address of a variable
  • * – The indirection or dereference operator * gives the content of the object pointed to by a pointer.

Advantages and Disadvantages of Pointers

Advantages of Pointers:

  • Pointers in C programming are helpful to access a memory location.
  • Pointers are an effective way to access the array structure elements.
  • Pointers are used for the allocation of dynamic memory and distribution.

Disadvantages of Pointers

  • A pointer can be dangerous when an attempt is made to access an area of memory that is either out of range of program or that does not contain a pointer reference to a legitimate object.
  • Pointer is dangerous when use of explicit type casts in converting between pointer types
  • It is dangerous when a NULL pointer is de-referenced, because on some computer it may return 0 and permitting execution to continue, or it may return the result stored in location zero, so it may produce a serious error.

Leave a Reply

Your email address will not be published. Required fields are marked *