------------------------------------------------------------------------------
MC logo
Basic Pointers
[^] CSc 220 Home
------------------------------------------------------------------------------
[Introduction] [Boolean and Control] [Functions] [Arrays and Pointers] [Dynamic Arrays] [Array Errors] [Command Array] [Standard Containers] [Structs and Classes] [Automatic Pointer] [Multi-File Programs] [Copying Objects] [Templates] [Inheritance] [Plain C I/O] [Type Odds And Ends] [Plain C Strings] [File I/O]
[Array Echo] [Basic Pointers] [Swap Using Pointers] [Arrays and Pointers] [Array Passing] [Integer Select Sort] [Integer Quick Sort] [Integer Library Sort] [Pointers and References]
basicp1.cpp
// Some pointer games.
#include <iostream>
using std::cout;
using std::endl;

int fred(int *z)
{
        int q = *z;
        *z = 15;
        return 2*q;
}

int main()
{
        int m = 5, n = 10;
        int *ip, *ip2;

        ip = &m;
        ip2 = &n;
        *ip = 77;
        *ip2 = -485;
        cout << "A: " << m << " " << n << endl;

        *ip2 = *ip;
        cout << "B: " << m << " " << n << endl;

        ip2 = ip;
        *ip = 100;
        *ip2 = 200;
        cout << "C: " << m << " " << n << endl;
        
        m = fred(&n);
        cout << "D: " << m << " " << n << endl;
}