From what I understand about pointers:
But I saw other code like this which works:Code:int k = 5; // create a new variable k with a value of 5 int *ptr; // create new pointer ptr ptr = &k; // make ptr point to the address of k *ptr = 7; // assign the value of 7 to the pointed address
I don't understand this because I thought that you can only assign a variable to *ptr and an address to ptr, but &k is an address of k. Can anyone explain this to me?Code:int *ptr = &k;