Hello guys,
I am trying this thing about pointer since a few days but still couldn't figure out. Guess I could use some help, thanks in advance.
Here is the problem:
Suppose, We have three pointers, *a,*b and *c, two variables, x and y. We shall assign the address of x to a and y to b. Now I want c such that it will hold the sum of the values that pointer a and b points.
In C++, the code fragment is like this:
1 2 3 4 5 6 7 8 9 10 11 12
int *a,*b,*c,x=3,y=2;
a=&x;
b=&y;
/*
Here should be the process that I cant figure out
*/
cout<<*c<<endl; //it will print 5
x=10;
y=5;
cout<<*c<<endl; //now it should print 15
If you don't want to overwrite x and y then you have to create another variable for the result and let *c pointer to that. (and manually compute the result everytime x and y changes)
I think you messing with some strange idea there that's not gonna work how you think you want it to work :P
If you don't want to overwrite x and y then you have to created another variable for the result and let *c pointer to that.
I didn't quite understand. I think what you meant is, I shall add x and y first, then store the sum to another variable z, then assign the address of z to c.
But that's not what I want. I just want to see if there is any way to make this "strange idea" possible!! :D