If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Have got error pointer

Originally Posted by Dintey

An error has reported,

Look at these lines

Code:

int a=2;
int *b=&a;
function(&b);

In the second line you take a pointer to the object a by preceding the variable with an ampersand. In the third line you take a pointer to the object b. Since b has type int*, &b has type int** (pointer to pointer to int). If instead you want to take get the value of what b points to, use *b.

Also, here

Code:

cout<<b;

you are printing the value of b, i.e. the memory address it is pointing to. You can get the value of what b is pointing to in the same way as above.

Cheers, D Drmmr

Please put [code][/code] tags around your code to preserve indentation and make it more readable.

As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Re: Have got error pointer

Originally Posted by Dintey

@D_Drmmr..... Can you write it for me please ?

I could, but I generally don't do that since I don't believe it will help you. If you want to see an example then search for one online and you'll find plenty. Then again, I can't imagine that the book you are studying (or your teacher) didn't provide any examples that show how to dereference a pointer. Reapplying that knowledge in another situation is what learning is all about. If you just copy a piece of code written by someone else, you have learned nothing - and that will come to haunt you for sure.

Cheers, D Drmmr

Please put [code][/code] tags around your code to preserve indentation and make it more readable.

As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky