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

Ryan Barone
April 18, 2022

In C++ programming, an asterisk is used 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.

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. 

Meet iD Tech!

Sign up for our emails to learn more about why iD Tech is #1 in STEM education! Be the first to hear about new courses, locations, programs, and partnerships–plus receive exclusive promotions! AI summer camps, coding classes for kids, and more!

By signing up you agree to our Privacy policy
Subscribe & Save!

Meet iD Tech!

Sign up for our emails to learn more about why iD Tech is #1 in STEM education! Be the first to hear about new courses, locations, programs, and partnerships–plus receive exclusive promotions! AI summer camps, coding classes for kids, and more!

By signing up you agree to our Privacy policy

Meet iD Tech!

Sign up for our emails to learn more about why iD Tech is #1 in STEM education! Be the first to hear about new courses, locations, programs, and partnerships–plus receive exclusive promotions! AI summer camps, coding classes for kids, and more!

By signing up you agree to our Privacy policy
Subscribe & Save!

Meet iD Tech!

Sign up for our emails to learn more about why iD Tech is #1 in STEM education! Be the first to hear about new courses, locations, programs, and partnerships–plus receive exclusive promotions! AI summer camps, coding classes for kids, and more!

By signing up you agree to our Privacy policy