+ 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?

9th Oct 2017, 6:56 AM
Adam
Adam - avatar
6 Respuestas
+ 7
E.g. Linked lists, binary tree data structures, etc. https://www.cprogramming.com/tutorial/lesson18.html
9th Oct 2017, 11:26 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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.
2nd Jan 2018, 1:34 PM
Dhar.m
Dhar.m - avatar
+ 1
Looking for a simple code example please.
9th Oct 2017, 6:56 AM
Adam
Adam - avatar
+ 1
But I could more easily type x=2 am I missing something?
9th Oct 2017, 9:50 AM
Adam
Adam - avatar
+ 1
yes I did
9th Oct 2017, 10:40 AM
Adam
Adam - avatar