What Does * (Asterisk) Mean in C++ Programming?

iD Tech in action

An asterisk is used in C++ to declare a pointer. Pointers allow you to refer directly to values in memory, and allow you to modify elements that would otherwise only be copied.

You could change an argument to use a reference, but every time you wanted to use that address, you would need to add ampersands (&) everywhere. Instead, the string variable can be changed using a pointer.

Creating Pointers

Again, a pointer points to a specific value stored at a specific address in a computer's memory. You can think of it as a variable for another variable's address.

To declare a pointer, use an asterisk (*). Below where input is declared, type:
string* pointer; 

To initialize a pointer, use an ampersand (&), which is an address-of operator. Below where the pointer is declared, type:
pointer = &input; 

That sets your variable, called pointer, to the address of input. 

Here is a quick breakdown to remember the different pointers and operators:

Still stuck? Get started with an Online Private Lesson in C++, where your child can learn more about the wide world of coding and development with the help and expertise of a dedicated, experienced instructor. 

A photo of Ryan

Ryan manages blog content at iD Tech, starting with the company in 2008. He earned his MBA from Santa Clara University after obtaining his Bachelor’s degree from Arizona State. Connect on LinkedIn!

Featured Posts

Categories

Authors

About iD Tech

iD Tech is the #1 tech camp on the planet, and world leader in youth STEM education, with programs held online and at 150+ global locations offering 50+ innovative tech courses: 

Coding camps
Video game camps
Robotics classes & camps
Creative arts classes & camps
All STEM camps

We've bet our reputation on recruiting the top instructors in the country. Our small classes ensure customized learning, leading to "a-ha moments" and awesome outcomes. Programs include:

On-Campus Programs

Online Tutoring

All Coding Courses