/* * You can (and often do) use the pointer declarator in combination with * the reference operator. */ void pointer_declarator_examples(){ int x; // declare an integer named x (currently uninitialized) int *ptr; // declare a pointer to an integer (currently uninitialized) ptr = &x; // set the value of ptr to be the address of x // note that here, & is used as the reference operator // also, even though x has no value, it does have an address std::cout << &x << endl; std::cout << ptr << endl; std::string s = "hello world!"; std::string *ptr_to_str = &s; std::string **ptr_to_ptr_to_str = &ptr_to_str; // no problem here! } /* Here are some simple examples of the dereference operator being used */ void dereference_operator_example(){ int x = 3; int *y = &x; // * as the pointer declarator. & as the reference operator. int z = *y; // * is used as the dereference operator. std::string s = "hello world!"; std::string *ptr_to_str = &s; std::string *ptr_to_str_2; ptr_to_str_2 = ptr_to_str; std::string s_2 = *ptr_to_str_2; }