Skip to main content
Engineering LibreTexts

23.3: Pointer Data Type

  • Page ID
    10543
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Pointer Data Type in C++

    A pointer variable is a variable that holds the address of a memory location. "Every variable is assigned a memory location whose address can be retrieved using the address operator &. The address of a memory location is called a pointer."1 The pointer data type allows us to designate a variable to hold an address or a pointer. The concept of an address and a pointer are one in the same. A pointer points to the location in memory because the value of a pointer is the address were the data item resides in the memory. Given an integer variable named age:

    int age = 47;

    We can create a pointer variable and establish its value which would be the done using the address operator[which is the ampersand or &] by:

    int * int_pointer = &age;

    The asterisk is used to designate that the variable int_pointer is an integer pointer [int *]. This means that whenever we use the variable int_pointer that the compiler will know that it is a pointer that points to an integer.

    In order to use pointers you will need to understand the indirection operator which is covered a supplemental link.

    Defintions

    Pointer
    A variable that holds an address as its value.

    Footnotes

    Tony Gaddis, Judy Walters and Godfrey Muganda, Starting Out with C++ Early Objects Sixth Edition(United States of America: Pearson – Addison Wesley, 2008) 597.


    This page titled 23.3: Pointer Data Type is shared under a CC BY license and was authored, remixed, and/or curated by Kenneth Leroy Busbee (OpenStax CNX) .

    • Was this article helpful?