// @topic W010601 Pointers
// @brief examples of new, [ ], and *
// main.cpp
#include <iostream>
int main()
{
// Examples dynamically allocating
// two blocks of memory:
// Allocate 100 double values.
// Note: you can use a variable to specify
// how many values we need:
int how_many = 100;
double* ptr_dbl = new double[ how_many ];
// Dynamically allocate 100 integers:
int* location = new int[ 100 ];
// location is a pointer to int
//
// location is a variable that stores
// addresses of ints
//
// pointer is a variable that stores
// addresses
// and it knows the type of data
// that it is pointing to.
std::cout << location[ 5 ] << '\n'; // print 6th integer
std::cout << location[ 0 ] << '\n'; // print first integer
std::cout << *location << '\n'; // print first integer
std::cout << *(location + 0) << '\n'; // print first integer
std::cout << *(location + 5) << '\n'; // print 6th integer
std::cout << (location + 5) << '\n'; // address of the 6th integer
return 0;
}