tags:

views:

124

answers:

3

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?

+7  A: 

You probably meant:

int k=7;
int *t=&k;
Ofir
+3  A: 

&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.

mkluwe
+1  A: 

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.

pmr