PointerTest4

PointerTest4 - result = g ( a[2] , n ) ; 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 f(int * p1, int * p2) { int m = 1 ; for (int i = 0; i < * p2; ++i) m = m * * p1 ; ++ p1 ; ++ * p2 ; return m; } int m = 1 ; for (int i = 0; i < p2; ++i) m = m * p1 ; ++ p1 ; -- p2 ; return m; } int main() { int a [ ] = { 4,2,3,5,4 } ; int n = 3 ; int result ; result = f ( a , & n ) ; cout << result << endl ; result = f ( a + 1 , & n ) ; cout << result << 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: result = g ( a[2] , n ) ; cout &lt;&lt; result &lt;&lt; endl ; cout &lt;&lt; &quot;a:&quot; &lt;&lt; a[0] &lt;&lt; &quot;, &quot; &lt;&lt; a[1] &lt;&lt; &quot;, &quot; &lt;&lt; a[2] &lt;&lt; &quot;, &quot; &lt;&lt; a[3] &lt;&lt; &quot;, &quot; &lt;&lt; a[4] &lt;&lt; endl ; cout &lt;&lt; &quot;n: &quot; &lt;&lt; n &lt;&lt; endl ; result = g ( a[n] , n ) ; cout &lt;&lt; result &lt;&lt; endl ; cout &lt;&lt; &quot;a:&quot; &lt;&lt; a[0] &lt;&lt; &quot;, &quot; &lt;&lt; a[1] &lt;&lt; &quot;, &quot; &lt;&lt; a[2] &lt;&lt; &quot;, &quot; &lt;&lt; a[3] &lt;&lt; &quot;, &quot; &lt;&lt; a[4] &lt;&lt; endl ; cout &lt;&lt; &quot;n: &quot; &lt;&lt; n &lt;&lt; endl ; }...
View Full Document

Ask a homework question - tutors are online