C++ programming question

Pretender

Banned
Mar 14, 2000
7,192
0
0
in the following:

void myfunction() {
int a;
for (a=0;a<10;a++)
cout << a;
}

a wouldn't be released from memory until the end of the function, right?

but in this:

void myfunction() {
for (int a=0;a<10;a++)
cout << a;
}

the a would get released when the loop was completed, right?

This is according to my teacher, and I never learned it on my own, so I just want to check to confirm this.
 

GL

Diamond Member
Oct 9, 1999
4,547
0
0
Yes that's what should happen, barring any compiler optimizations.

-GL
 

mikee

Senior member
Jan 6, 2000
570
0
0
to confirm, yes. you gotta look at the scope of the variable when it's created on the stack.
 

GL

Diamond Member
Oct 9, 1999
4,547
0
0
Pretender,

The guy above me brought up a good point about the stack. If you hadn't done so, it's probably a good idea to familiarize yourself with memory management and all the &quot;stack and heap&quot; stuff related to programming. Once you get this stuff down, it's applicable across all languages and is very useful.

-GL
 

Pretender

Banned
Mar 14, 2000
7,192
0
0
I understand basically about how all that stack stuff works, but I never actually watched it carefully. I think I'll re-examine that soon. Good idea :)
 
Jun 18, 2000
11,197
769
126


<< What kind of post is &quot;..&quot;?? >>


No worries, mi amigo. I'm sure (s)he will be banned soon enough. I've seen several of these nef posts already. By the now, the mods are sure to have seen the same.
 

beer

Lifer
Jun 27, 2000
11,169
1
0
There's a thread in Forum Issues about this particular user.
He/she will stop soon.