My Take on Pointers

Greetings!

So Section_03 covered Pointers, which I think were a tiny bit confusing, but I think I understand them.

I’ll use the analogy of a shopping mall.
Variables are like the stores in the mall, and Pointers are like the directional signs that point you to the correct store.
By seeing the directional sign, you can find the stores much more quickly.

When you use the ‘&’ symbol as in int = &myvar; you are accessing the ADRESS of the variable.
When you use the ‘*’ symbol as in int = *myvar; you are accessing the CONTENT of the variable.

Am I correct?

This is an easy to understand answer. Im hoping someone can confirm it as this is a good explanation for how i understand it to be as well.

Thanks

1 Like

As you know every data type has some address even pointers too.So when we write ’ &’ it returns the address.When we use ’ * ’ it means that we want to access its Content. For Example

Var is an int data type whose address is 2000.Lets say we decalare a ptr and we assign the address of var.
(int *ptr = &var)

So ptr will store 2000 which is the address of Var.Now When we write *ptr then our sweet friend compiler will know that it has to access the content at 2000th address and the content at 2000 is var value .

If you still didn’t get it then its perfectly OK it may take some time :slight_smile:

Privacy & Terms