pointer confusion

my book isnt being very clear on this, so i figured i would come here for the answer. can pointers be used in functions that they arent declared? from what im understanding in my book, they should be able to, but when i try something like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void pointer_output();
int main()
{
int *pointer = new int;
*pointer = 50;

pointer_output();

return 0;
}

void pointer_output()
{
std::cout << *pointer;
}


i keep getting told that its an undeclared identifier by my compiler. i know that you have to declare variables within functions, but i thought that pointers were used everywhere, if im wrong then thats cool, im just trying to get this right.

No, they can't. They are just like any other variable in that respect.
thanks, that helps a lot.
Topic archived. No new replies allowed.