So in my last problem, someone said "Use a pointer" (or something like that). When I googled it. It had to do with memory blocks (at least, I think). So what is it? And, oh yeah, can you make it as simple as possible. I have tried seeing what it does with this:

string* smile;
smile[50];
cout << smile;

There is a lot to learn. As most things, it will take time and practice. So don't expect it get it soon. There are many comprehensible tutorials about them over the net, so go search them. And maybe come back with a more specific question.

Ok. How about, what are there purpose in there short little compiled lives?

I don't understand your last post.
I can tell you that when you make some variable, it magically appears in the computers memory. Magic.
A pointer contains a memory address. They are used to access whatever is a that memory position.

References and pointers are basically the same.
Except pointers may change their address.

Example:

float* numPtr = new float(10); // the new operator creates a float that isn't associated to a scope. Means it lives until it is manually deleted.
std::cout << *numPtr; // We have to write * in front of our pointer, otherwise the pointers contained address is output, instead of the value of the memory at that address
numPtr = new float(133);
std::cout << *numPtr; // we output the same pointer, but it has a different value. MAGIC!
// Oh well, now where here. What now? Oh yes, we gotta delete the floats we created:
delete numPtr;
delete ... // Oh gawd, we don't have the address of the other float anymore. This is a memory leek. But don't worry, exit the app and your OS will delete the associated memory anyway.

So what is the point of it?
Well in C++ you may have a whole lot of objects, but only one is to be active at a time. So you have a pointer, and your code will work with that pointer. But you dynamically change the address in that pointer, and the code has a whole other meaning.
Also, when youre passing a big object as a parameter in a function, you may pass a pointer or reference, instead of a copy of the object. This saves memory and CPU to copy the memory.

I don't understand your last post.
I can tell you that when you make some variable, it magically appears in the computers memory. Magic.
A pointer contains a memory address. They are used to access whatever is a that memory position.

References and pointers are basically the same.
Except pointers may change their address.

Example:

float* numPtr = new float(10); // the new operator creates a float that isn't associated to a scope. Means it lives until it is manually deleted.
std::cout << *numPtr; // We have to write * in front of our pointer, otherwise the pointers contained address is output, instead of the value of the memory at that address
numPtr = new float(133);
std::cout << *numPtr; // we output the same pointer, but it has a different value. MAGIC!
// Oh well, now where here. What now? Oh yes, we gotta delete the floats we created:
delete numPtr;
delete ... // Oh gawd, we don't have the address of the other float anymore. This is a memory leek. But don't worry, exit the app and your OS will delete the associated memory anyway.

So what is the point of it?
Well in C++ you may have a whole lot of objects, but only one is to be active at a time. So you have a pointer, and your code will work with that pointer. But you dynamically change the address in that pointer, and the code has a whole other meaning.
Also, when youre passing a big object as a parameter in a function, you may pass a pointer or reference, instead of a copy of the object. This saves memory and CPU to copy the memory.

That is exactly what I wanted to know!


thank you!

Glad that I could help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.