Click here to Skip to main content
15,923,015 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: scope in functions Pin
toxcct15-Apr-07 22:12
toxcct15-Apr-07 22:12 
GeneralRe: scope in functions Pin
CPallini15-Apr-07 22:05
mveCPallini15-Apr-07 22:05 
GeneralRe: scope in functions Pin
minkowski15-Apr-07 22:12
minkowski15-Apr-07 22:12 
GeneralRe: scope in functions Pin
toxcct15-Apr-07 22:15
toxcct15-Apr-07 22:15 
GeneralRe: scope in functions Pin
CPallini15-Apr-07 22:53
mveCPallini15-Apr-07 22:53 
GeneralRe: scope in functions Pin
toxcct16-Apr-07 10:01
toxcct16-Apr-07 10:01 
GeneralRe: scope in functions Pin
CPallini16-Apr-07 11:12
mveCPallini16-Apr-07 11:12 
AnswerRe: scope in functions Pin
BadKarma15-Apr-07 22:11
BadKarma15-Apr-07 22:11 
Let me explain what happens.
int x = 6;
creates a int variable on the stack and sets it to the value 6
int * ptr = &x;
creates a pointer to integer variable on the stack and sets the value to the stack address where x is located.
return ptr;
retuns to the calling function lowering the stack pointer to where it was before calling the function.
and returns the value of the pointer. The pointer is now addressing somewhere in the unused stack space. The values of the stack remain there until the are overwritten/needed for other variables, or other function calls.

In other words this is not a good practice and should never be used.

I don't know what you mean about the copy constructor, since int isn't a class so it doesn't have a copy constructor in the way you think.

codito ergo sum

GeneralRe: scope in functions Pin
minkowski15-Apr-07 22:20
minkowski15-Apr-07 22:20 
GeneralRe: scope in functions Pin
toxcct15-Apr-07 22:25
toxcct15-Apr-07 22:25 
GeneralRe: scope in functions Pin
minkowski15-Apr-07 22:29
minkowski15-Apr-07 22:29 
GeneralRe: scope in functions Pin
toxcct15-Apr-07 22:31
toxcct15-Apr-07 22:31 
GeneralRe: scope in functions Pin
Cedric Moonen15-Apr-07 22:33
Cedric Moonen15-Apr-07 22:33 
GeneralRe: scope in functions Pin
minkowski15-Apr-07 22:41
minkowski15-Apr-07 22:41 
GeneralRe: scope in functions Pin
jhwurmbach15-Apr-07 22:57
jhwurmbach15-Apr-07 22:57 
Questionerror C2653: 'TryIt' : is not a class or namespace name Pin
nathan715-Apr-07 21:10
nathan715-Apr-07 21:10 
AnswerRe: error C2653: 'TryIt' : is not a class or namespace name Pin
Programm3r15-Apr-07 21:24
Programm3r15-Apr-07 21:24 
AnswerRe: error C2653: 'TryIt' : is not a class or namespace name Pin
toxcct15-Apr-07 22:23
toxcct15-Apr-07 22:23 
AnswerRe: error C2653: 'TryIt' : is not a class or namespace name Pin
cp987616-Apr-07 0:00
cp987616-Apr-07 0:00 
GeneralRe: error C2653: 'TryIt' : is not a class or namespace name Pin
Michael Dunn16-Apr-07 10:24
sitebuilderMichael Dunn16-Apr-07 10:24 
GeneralRe: error C2653: 'TryIt' : is not a class or namespace name Pin
Mark Salsbery16-Apr-07 10:31
Mark Salsbery16-Apr-07 10:31 
GeneralRe: error C2653: 'TryIt' : is not a class or namespace name Pin
cp987616-Apr-07 18:44
cp987616-Apr-07 18:44 
GeneralRe: error C2653: 'TryIt' : is not a class or namespace name Pin
nathan716-Apr-07 23:46
nathan716-Apr-07 23:46 
GeneralRe: error C2653: 'TryIt' : is not a class or namespace name Pin
Mark Salsbery17-Apr-07 6:25
Mark Salsbery17-Apr-07 6:25 
GeneralRe: error C2653: 'TryIt' : is not a class or namespace name Pin
JudyL_MD17-Apr-07 8:00
JudyL_MD17-Apr-07 8:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.