/*----
  signature: main: void -> int
  purpose: playing with pointers

  compile using:
    g++ ptr-1.cpp -o ptr-1
  run using:
    ./ptr-1

  by: Sharon Tuttle
  last modified: 2022-09-29
----*/

#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main()
{
    cout << boolalpha;

    cout << "pointer playing!" << endl;

    int *quant_ptr;  // type of quant_ptr
                     //    is pointer-to-int
    double* num_ptr; // type of num_ptr
                     //    is pointer-to-double

    double quant = 4.0;

    num_ptr = &quant;

    cout << "quant:    " << quant << endl;
    cout << "&quant:   " << (&quant) << endl;
    cout << "num_ptr:  " << num_ptr << endl;
    cout << "*num_ptr: " << (*num_ptr) << endl;

    quant = 3.145;

    cout << "*num_ptr: " << (*num_ptr) << endl;

    *num_ptr = 7;

    cout << "quant: " << quant << endl;

    int *val_ptr;

    val_ptr = new int;
    *val_ptr = 13;

    cout << "val_ptr: " << val_ptr << endl;
    cout << "*val_ptr: " << (*val_ptr) << endl;

    // good style: deallocate using delete
    //   what you allocate using new

    delete val_ptr;

    // if program is not ending then,
    //     GOOD STYLE to set a pointer
    //     you have deallocated to NULL
    //     (or to point to something else)

    val_ptr = NULL;

    return EXIT_SUCCESS;
}