what makes a pointer so cool ... why do we even use them
what makes a pointer so cool ... why do we even use them
They improve efficiency and memory usage, they increase readability and allow for more compact code, they allow us to create linked data structures such as lists and trees, shall I go on? Just take it on faith that pointers make your job as a programmer much easier.
-Prelude
My best code is written with the delete key.
If you are just learning C++, then wait a little bit. You will see in time why they are so important. For example, with pointers u can create arrays whose size is inputted by the user. Or even better, you can create array-like groups that can be increased in size at any time.
I beleive you could do that without pointers...
Or you could do it with 2D Arrays.Code:cout<<"Enter the size"<<endl; cin>>size; char array[size]; //That would work wouldn't it?
No, you cannot. The size of an array has to be a constant...
However, you could do something like
#define ARRAY_SIZE 8;
char array[ARRAY_SIZE];
Well I'm quite a ways past arrays and I don't see the reason for pointers yet. I must be missing something fundamental. Why is it that linked lists, dynamic arrays, etc can only be created on the heap rather than the stack.
with pointers u can change the values assigned to a variable in any function
pointers are always used in HL programs.
for sxample
u assigned x;
and then with pt u may later change the value of x into watever u want, usually it is used where user input is req'd in the program.
so never say no to pointers unless u a noob and are not rdy to move to next step.
Pointers are _HARD_ to understand. The books i've read did not pay enough attention to pointers... and I was forced to look elsewhere.
I really don't think the pointer tutorial on this website is sufficient either... what really helped me learn was diagrams of memory addresses and such.
i think i'm starting to grasp it ... with pointers crap can be changed dynamically by funs in the program ... but can't stuff on the stack be changed like this to?
that's supposed to be funcs
This should give you everything you need to know..
Best pointer tutorial I've found: http://www.cplusplus.com/doc/tutorial/tut3-3.html
I think it also lists some of the possible uses for pointers.
pointers allow you to own pieces of data without naming it. think about it this way: if you had 20 cattle named beth, sarah, julia, kris.... and you had 20 other cattle who all responded to "hey you!", which can you manipulate easier? which group of cattle is more flexible in your eyes?
Are you insinuating that they are not used in lower level programming? I use pointers all the time in Assembly. Personally, I think handling pointers in assembly is better (even more fun) than C++. I encourage all of you to program in assembly. x86 assembler is like a drug.Originally posted by dayknight
with pointers u can change the values assigned to a variable in any function
pointers are always used in HL programs.
for sxample
u assigned x;
and then with pt u may later change the value of x into watever u want, usually it is used where user input is req'd in the program.
so never say no to pointers unless u a noob and are not rdy to move to next step.
-Mike
{InFeStEd-ArCh0n}
Pointers are your Best FRIEND
YES THEY ARE...
LEARN THEM HARDCORE and USE THEM ALOT...
If you dont, i can gaurentee you , you wont last long in the C++ world.
LB0: * Life once school is done
LB1: N <- WakeUp;
LB2: N <- C++_Code;
LB3: N >= Tired : N <- Sleep;
LB4: JMP*-3;
i meant that they are always used in HL programs, well u could use them in LL programs, but then u dont really need them in small prgrams.Originally posted by InFeStEd-ArCh0n
Are you insinuating that they are not used in lower level programming? I use pointers all the time in Assembly. Personally, I think handling pointers in assembly is better (even more fun) than C++. I encourage all of you to program in assembly. x86 assembler is like a drug.