Pointer
I have pretty good grip on pointers but I think I missed something in my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
using namespace std;
void pointerfunction(int* piPointer1, int* piPointer2);
int main()
{
int pointer1;
int pointer2;
pointerfunction(&pointer1, &pointer2);
cout << pointer1 << endl;
system("PAUSE");
return 0;
}
void pointerfunction(int* piPointer1, int* piPointer2)
{
cout << "Enter 2 numbers" << endl;
cin >> piPointer1 >> piPointer2;
}
|
And thanks for reading this. If you could tell me what is wrong that would be great.
Last edited on
At line 19: you cant set a value of a pointer, to change the value stored on the location pointed you should use
*piPointer1 instead of
piPointer1.
I think your function would be better if it takes arguments passed by reference instead of using pointers, try to see this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
int main()
{
int numb1,numb2;
referencefunction(numb1, numb2);
cout << numb1 << endl;
system("PAUSE");
return 0;
}
void referencefunction(int& Ref1, int& Ref2)
{
cout << "Enter 2 numbers" << endl;
cin >> Ref1 >> Ref2;
}
|
Last edited on
thanks for the hep now only about 900 pages of book to go
Topic archived. No new replies allowed.