Learn

So now we learned what a pointer is and how to create one, but is there a way to obtain the value pointed to by the pointer?

The asterisk sign * a.k.a. the dereference operator is used to obtain the value pointed to by a variable. This can be done by preceding the name of a pointer variable with *.

int blah = *ptr;

The double meaning of the * symbol can be tricky at first, so make sure to note:

  • When * is used in a declaration, it is creating a pointer.
  • When * is not used in a declaration, it is a dereference operator.

Instructions

1.

Print out *ptr using std::cout.

What do you think it will output?

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?