PointerTest4

# PointerTest4 - result = g a[2 n cout<< result<<...

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

#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 ;
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 << result << endl ; cout << "a:" << a[0] << ", " << a[1] << ", " << a[2] << ", " << a[3] << ", " << a[4] << endl ; cout << "n: " << n << endl ; result = g ( a[n] , n ) ; cout << result << endl ; cout << "a:" << a[0] << ", " << a[1] << ", " << a[2] << ", " << a[3] << ", " << a[4] << endl ; cout << "n: " << n << endl ; }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online