Reference - Deference Operator


Reference Operator (Address Operator) :-

  • The address operator(&) is a unary operator which gives the address of its operand. it is also called reference operator.
  • Thus, if x is a variable then the expression &x gives the address of memory location of x. If x occupies more than one byte of computer memory ,then &x returns the starting address of x
  • Consider the following statements:
    int x;
    int *p;

  • The first statement creates a simple integer x.the second statement creates a pointer p which is capable of pointing to any variable of dataype int. It should be noted that p is currently not pointing to any variable.
  • We may now write p=&x; this statement stores address of variable x in pointer p. We may now say that p points to x or p reference x.
  • This procedure of storing address of x in p is called referencing and it is achieved using reference operator "&".

Dereference Operator ( Value At Operator Of Indirectional Operator ) :-

  • Consider the following statement :
    int x=5;
    int *p;
    p=&x;

  • The value 5 in the above example can be accessed through two ways,the first being that we directly write x.

  • The indirection operator can be used only with a pointer variable . When used with a pointer, it gives us the value of the variable to whom the pointer points.

  • The placement of indirection operator before a pointer is said to dereference the pointer and this procedure is sometimes called dereferencing.

  • Print Page