Obtaining address of pointer in C with and without ampersand, what's the difference?

前端 未结 3 1581
误落风尘
误落风尘 2020-12-12 03:55

I am having difficulty understanding this guide\'s code on pointers in C. I thought that you needed an ampersand to reference the address of a pointer, but the guide\'s code

3条回答
  •  遥遥无期
    2020-12-12 04:14

    you used

    int var = 20;
    int *ip;
    ip = &var;
    

    and you printed &var, ip, &ip *ip

    Here &var and ip will indicate the address of the memory where 20 is saved. And *ip will indicate the value 20. And the most important thing what you wanted is &ip. When int *ip is called, the memory region for this variable will be created. so ip occupy some memory region. When you print &ip, then this will indicate the memory address where ip(contains the address of var) is saved.

提交回复
热议问题