Pointers

How do you edit an array in one function using pointers in a different function.
Here is functions

Function Prototype:
void userNumbers(int *);

Main Function:
1
2
3
4
5
int main (){  
	int usernum [4];		
	cout <<usernum[0]<<usernum[1]<<usernum[2]<<usernum[3]<<usernum[4];
		return 0;
}


Other Function:
1
2
3
4
void userNumbers(int *aPtr){
	cout << "Please enter your lottery numbers seperated by spaces";
	cin >> aPtr[0],aPtr[1],aPtr[2],aPtr[3],aPtr[4];
	}


How can i make usernum be editied in userNumbers function?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>


void userNumbers( int *aPtr, int n )
{
	std::cout << "Please enter your " << n << " lottery numbers seperated by spaces";

	for ( int i = 0; i < n; i++ ) std::cin >> aPtr[i];
} 


int main ()
{  
	const int N = 4;
	int usernum[N];

	userNumbers( usernum, N );		

	for ( int i = 0; i < N; i++ ) std::cout << usernum[i] << ' ';
	std::cout << std::endl;
		
	return 0;
} 
use the function

void userNumber(int A[]);
and call it like this

userNumber(usernum);
Topic archived. No new replies allowed.