The book says:
But I write a program with function clone2
It works without any error.
Is what book says still correct?
Thanks
The book says:
But I write a program with function clone2
It works without any error.
Is what book says still correct?
Thanks
The book is correct, although the use of the term temporary variable for a variable with automatic storage duration only adds to the confusion. Furthermore the book appears to omit the fact that that the program behaviour is undefined.
Hence your compiler is allowed to do anything, including giving the impression that what you're doing is legal.
Short answer: don't do it.
The local variable newguy
will be created/allocated on the stack-memory. if you call another function with some local variables and assign values to them, they will overwrite the Memory of your newguy
. So it might work, if you Access the variable after a call to clone2
- but you might not get the original Content of newguy
, if you call some other function before accessing newguy
.
That's why it is not a good idea to do it ;-)