All right, thank you friends! i'm gonna look to know more about this.
However i do not understand why there is "const" in this declaration... May be it's too technical for my beginner brain... but i'll understand, some day... :)
When you put a 'string literal' in your code like this "some text" the compiler actually returns the place in memory where that text is stored. That place in memory is an 'address of' or 'pointer to' the text itself. So it is a char*. But more than that, the text itself is stored in an area of memory that can not be changed. So it is typed as const.
So the 'type' of a string literal is a constchar* (a pointer to an array of constant characters).
because it is.
think about it: it's typed into the source code, in "quotes", embedded in
at compile time, all wrapped up in the executable file.
If you open the executable in an editor you'll see it there.
so It is constant. You wouldn't want to write to the program,
in normal civilised company while running would you?
It would probably blow up.
well, you haven't named a variable.
if it's in quotes it's a const char * as explained.
if you assign it to a string it will be copied.
that string of characters will still exist in the binary file.
you need to learn about "the stack" and automatic variables,
as a starting point.
I am afraid you have a lot to learn!
but it is all good fun.
Constness only indicates that you pledge not to modify a specific item... this is good when you have objects in memory that should not be modified (except in special circumstances), or cannot be modified (because you or your program don't have that privilege). Making a thing const is useful because the compiler can check to make sure you aren't trying to modify things you aren't supposed to modify...
Notice how if the replacement string were "Really, really Stupid", then the program would be modifying itself in places where it shouldn't (outside of the space allocated to store the "Stupider" string -- and probably somewhere in the program's code).