alkhoudri posted:
> char * CurrentString = "\0";
It's illegal to alter a string literal; in light of this, it's best to use:
char const *CurrentString = "\0";
> void function01()
> {
> ...
> strcpy(CurrentString, "aString");
> ...
> }
>
> And the application doesn't crash !!!
> Do you have any idea why ?
You're writing to memory which isn't yours to write to. Either of these
things will happen:
(1) The system will deny the request and continue on.
(2) The system will deny the request and terminate the program.
(3) The system will allow the request and continue on.
(4) The system will allow the request and the program will crash.
(5) Internet Explorer will be launched and it will go to
www.howstuffworks.com.
Bottom line: Undefined Behaviour.
> For me, it's just out of the question to copy a string in an
> unallocated space (pointed to by CurrentString in the above example).
The Standard agrees.
--
Frederick Gotham