+ 4
Another pointer question.
Could someone provide a really simple example of a situation where I would want to use pointers instead of just setting another variable as x. To me it seems to be all the same, *p is a variable and takes up a place in memory an so does another variable. If I change the original variable x, then both the values of l and y will change, so what's the use of holding an address? If I really want to I can always access the address of d using &x. So in short why is *p = x better than y = d?
6 ответов
+ 7
E.g. Linked lists, binary tree data structures, etc.
https://www.cprogramming.com/tutorial/lesson18.html
+ 3
I may not fully get the point, but the purpose of declaring a pointer (i.e using int * p) is because unless you use a struct, there is no other data type that can store different variable types i.e 0×2fee34 (which is the address name). Using pointer declaration is like telling the computer that just store this contrasting value in this 'variable'.
But why declare pointers you may ask?
Pointers are an important in coding. You,ll surely get the hang of it.
+ 1
Looking for a simple code example please.
+ 1
But I could more easily type x=2
am I missing something?
+ 1
yes I did