Skip to main content
Engineering LibreTexts

2.1: Pointer Review

  • Page ID
  • Pointers are symbolic representation of addresses. They enable programs to simulate call-by-reference as well as to create and manipulate dynamic data structures. It’s general declaration in C/C++ has the format:


    datatype *var_name;

    int *ptr;   //ptr can point to an address which holds int data


    Here is a visual example of how pointers work:
    Image that shows how pointers work and hold addresses and variables hold values

    How to use a pointer?

    • Define a pointer variable – you must use an asterisk (*) when defining a pointer variable. All three of the following are valid – they are the same:
      • int *ptr;
      • int * ptr;
      • int* ptr;
    • Assigning the address of a variable to a pointer using unary operator (&) which returns the address of that variable.
    • Accessing the value stored in the address using unary operator (*) which returns the value of the variable located at the address specified by its operand.

    Adapted from:

    "Pointers in C/C++ with Examples" by Abhirav Kariya, Geeks for Geeks is licensed under CC BY 4.0 

    • Was this article helpful?