2021年1月25日星期一

What is the difference between a pointer and a normal variable?

This question might be a bit broad. I'll try to narrow down what I'm really asking.

I know that the data in a pointer is allocated on the heap, and the address is allocated in the stack. I also know how the stack works ("popping in and off memory"). Normal variables are allocated on the stack. To my understanding, pointers are normal variables that the computer interprets as memory addresses.

I am learning C, and I see lots of function return values and examples with pointer variables, not stack variables. What makes pointers preferred over "normal" variables?

In C and C++, why are pointers everywhere? What makes them so special? Is it a performance boost, or what? I know they're good because of dynamic memory, but lots of places where pointers are used don't really need to be dynamic.

https://stackoverflow.com/questions/65895760/what-is-the-difference-between-a-pointer-and-a-normal-variable January 26, 2021 at 12:06PM

没有评论:

发表评论