PointersInFunctions

PointersInFunctions - squareIt(&y) ; cout...

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

View Full Document Right Arrow Icon
#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 ;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

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

Ask a homework question - tutors are online