C – Pointer

      Prev                                                                                              Next

  • C Pointer is a variable that stores/points the address of the another variable.
  • C Pointer is used to allocate memory dynamically i.e. at run time.
  • The variable might be any of the data type such as int, float, char, double, short etc.

Syntax : data_type *var_name;
Example : int *p;  char *p;

  • Where, * is used to denote that “p” is pointer variable and not a normal variable.

Key points to remember about pointers in C:

  • Normal variable stores the value whereas pointer variable stores the address of the variable.
  • The content of the C pointer always be a whole number i.e. address.
  • Always C pointer is initialized to null, i.e. int *p = null.
  • The value of null pointer is 0.
  • & symbol is used to get the address of the variable.
  • * symbol is used to get the value of the variable that the pointer is pointing to.
  • If pointer is assigned to NULL, it means it is pointing to nothing.
  • Two pointers can be subtracted to know how many elements are available between these two pointers.
  • But, Pointer addition, multiplication, division are not allowed.
  • The size of any pointer is 2 byte (for 16 bit compiler).

Example program for pointer in C:

Output:

50
 

      Prev                                                                                              Next

Share this C Programming tutorial with your friends

Facebook Twitter Linkedin





C Programming Tutorial | Terms of use | Suggestions/Contact Us | Disclaimer