to pass pointers to functions (pass by pointer).

Okay so im playing around with pointers.
i have given P the address of x = 10.
But im having issues with incrementing the 10?
I cant seem to call the doSomething function in my main although in my (school notes ive been given they're out of the function).
I'm stuck please help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #include "iostream"
using namespace std;
void doSomething(int *);
void main() 
{

	int x = 10;
	int *p;
	p = &x;
//	doSomething(pX);				//calling function isnt working? WHY?? undeclared identifier?

	cout << *p <<endl;				// p = 10.

	
	system("pause");
	
}
void doSomething(int *pX)
{	
	
	(*pX)++;
	
}
On line 10, you are using "pX" instead of "p".

10
11
12
13
14
doSomething(p);

//Alternatively

doSomething(&x);
Topic archived. No new replies allowed.