I have two questions about pointers:
Code:
#include <iostream.h>
void somefunc(int * fptr)
{
*fptr += 250;
}
void somefunc2(int * fptr2)
{
*fptr2 = 450;
}
void somefunc3(int * fptr3)
{
*fptr3 ++;// This doesn't work.
}
main()
{
int x = 3;
int * Xaddr = &x;
cout << x << endl;
somefunc(Xaddr);
cout << x << endl;
somefunc2(Xaddr);
cout << x << endl;
somefunc3(Xaddr);
cout << x << endl;
return 0;
}
Yet, strangely, the same line here does:
Code:
#include <iostream.h>
void somefunc(int * fptr)
{
*fptr += 250;
}
void somefunc2(int * fptr2)
{
*fptr2 = 450;
}
void somefunc3(int * fptr3)
{
*fptr3 += 1; // This does work.
}
main()
{
int x = 3;
int * Xaddr = &x;
cout << x << endl;
somefunc(Xaddr);
cout << x << endl;
somefunc2(Xaddr);
cout << x << endl;
somefunc3(Xaddr);
cout << x << endl;
return 0;
}
My two questions are thus:
1.) In cases like this, does the ++ operator not work?
2.) Is this one of the primary uses of pointers? (Through functions)