PointersInFunctions

# PointersInFunctions - squareIt&y cout<<"y...

This preview shows page 1. Sign up to view the full content.

#include <iostream> using namespace std ; int square (int *n) { return *n * *n ; } void squareIt (int *n) { *n = *n * *n ; } int inc_pre(int *n) { ++ *n ; return *n ; } int inc_post(int *n) { int t = *n ; ++ *n ; return t ; } int * mkSingleSquare (int n) { int *t = new int ; *t = n*n ; return t ; } int * bigProblem(int n) { int square = n * n ; return &square ; } int main() { int x = 4 ; int y = square (&x) ; cout << "y is " << y << endl ;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: squareIt(&y) ; cout << "y is " << y << endl ; int a = 4, b = 4, c, d ; c = inc_pre(&a); d = ++b; cout << "a=" << a << ", b=" << b << ", c=" << c << ", d=" << d << endl; a = 4 ; b = 4 ; c = inc_post(&a); d = b++; cout << "a=" << a << ", b=" << b << ", c=" << c << ", d=" << d << endl; int *z = bigProblem(4) ; cout << "z is " << z << endl ; }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online