Suppose we have a variable k
which is equal 7:
int k=7;
int t=&k;
But this does not work. What's the mistake?
Suppose we have a variable k
which is equal 7:
int k=7;
int t=&k;
But this does not work. What's the mistake?
&k
takes the address of k
. You probably mean
int *t = &k;
I have a good read for you: Alf P. Steinbach's pointer tutorial.
You declare t as of type int
and try to assign a value of type int*
. int*
cannot implicitely cast to type int
which leads to the error you are observing. The solution is simple: declar t as int*
. However, it seems you have no deeper understanding of pointers so you should fix that first before trying anything else.