C - POINTER


Address of memory location

  • Within computer's memory , every data occupies some memory location . The number of memory location required to store a data depends upon type of data (i.e. datatype)

  • for example, a single character will typically be stored in 1 byte(8 bits) of memory,an integer usually requires 2 bytes(16 bits). A floating variable may require 4 bytes(32 bits) and a Double may require 8 bytes.

  • Suppose v is a variable that represent some particular data item . The compiler will automatically assign some memory location for this data item.

  • The data item can be access if we know the location of The first memory location.Adjacent memory locations within a computers are numbered consecutively from beginning to end of memory area.The numbers associated with each memory location is known as memory location's address.
  • Most computer use hexadecimal number to designate the addresses of consecutive memory locations,though some computers use octal numbering system.

  • The address of variable x can be determined by expression &x, where '&' is unary operator called address operator , which evaluates address of its operand.

Pointer

  • A pointer is variable that stores memory address of other variables.
  • It does not contain any integer, float , character or double value but contains merely address of some variable.

DECLARATION OF POINTER

  • Like other variable pointer variable must be declared before they can be used in a C program.
  • When pointer variable is declared,the variable name must be preceded by by an asterisk (*).
  • The datatype appears in declaration refers to the variable to whom the pointer points rather the the pointer itself.
  • Thus, a pointer declaration may be written in general terms as ;
    datatype *pointer_variable_name; here datatype depends on the factor that pointer is pointing to variable of which datatype.
  • eg.
    int *p1,*p2;
    declares that pv and px as pointers which can point to variables of datatype int i.e. they can store address of variables of datatype int.

  • Print Page