return a pointer to an array from function

On this line of code *m = arrayAllocator(size); I am getting an error, line 12, for *m saying that "a value of type "int" cannot assigned to an entity of type "int". I am trying to return a point to an array from a 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
25
26
27
28
 int *arrayAllocator(int);

int main()
{

	
	int size; 
	int *m;

	cout << "How big is the array" << endl;
	cin >> size;
	*m = arrayAllocator(size);

	
	return 0;
}

int *arrayAllocator(int s){
	int *arry;
	//dynamic memory 
	arry = new int[s];
	//storing numbers in the array with a loop
	for (int i = 0; i < s; i++){
		cout << "What is the values being stored? " << endl;
		cin >> arry[i];
	}
	return arry;
}
Last edited on
You cant convert from int * to int .

m is already declared as a pointer to an integer in line 8 as int * .

calling *m dereferences m to an integer.

Fix it by replacing *m in line 12 with m .
Topic archived. No new replies allowed.