Understanding Arrays, Pointers, Operators, and Friends in C++

Overview

What are Arrays

string groceryList = [5];
groceryList[0] = “Tomatoes”;
// Another way to intialize Arrays
string groceryList[] = { "Tomatoes", "Potatoes", "Carrots" };
// This errors out, because index is out of bounds of Array
string groceryList[2] = {};
cout << groceryList[4] << endl;

What are Pointers

string message = “Tacos are delicious”;// * operator creates a shortcut to the value
string *shortcut;
// & operator gets the memory location of a variable
shortcut = &message;

// Returns memory address of 0x738d1e8a2370
cout << shortcut << endl;
// Returns Tacos are delicious
cout << *shortcut << endl;

What are Operators

Examples of Operators

What are Friends

class PersonOne {
friend class PersonTwo;
...
}

Key Takeaways

--

--

--

I am working toward a simpler, more meaningful world. kristofferhebert.com

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kristoffer Hebert

Kristoffer Hebert

I am working toward a simpler, more meaningful world. kristofferhebert.com

More from Medium

Understanding C++ pointers in an array using [], * and & with a code example

Understanding All the Details of C++ Const

WTF is a linked list — and why should I care?