What does a *pointer before function mean?

I was wondering what magic does a * pointer before function actually do? Today our programming teacher asked us to look into it and explain it in the next class!

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> 
using namespace std;
int *binary(int []);

int main() 
{ 
	int arr[] ={1,2,3,4,5,6,7,8,9,10};
	int z = *binary(arr);

	for(int i = 0; i<=9; i++)
	{
		cout<<z;
		z++;
	}
	return(0); 
}

int *binary(int arr[])
{
	for(int i = 0; i<=9; i++)
	{
		return arr;
	}
}


Any one please explain! I'm new to pointers. Thanks!
Last edited on
The return type of the function named binary is int *, meaning it returns a pointer to an integer. Don't let the alignment/spacing of the asterisk confuse you - different programmers align it with different spacing according to their preferences, but alignment and spacing never change the meaning of code in C++.
I think the OP meant here:
int z = *binary(arr);
All this does is gives the variable the pointer points to.
Last edited on
Topic archived. No new replies allowed.