programing

M

mc110403106

#include <iostream.h>
main()
{
long z,i,b;
cin >> z;
cout << z;
for (i=0;i<z;i++)
{
for (int c=0;c<z;c++ )
{
long ac;
/*sir i want here to create variable type long (ac)again and again
,a1,a2,a3..... but only one address variable created i wana see how
much memoryy decrease with thousands of long variable*/

cout << "p" << '\n' << &ac;
}

}

}
 
V

Victor Bazarov

And why, exactly?

To verify an assumption, perhaps.
If you just declare a variable but never use, there's a good chance that
the compiler will optimize it away, so it will not take any memory.

If it's a member of a class, or an element of an array, this will not
hold necessarily.
And even if it did, why do it the hard way? The amount of bytes that a
variable of type 'long' takes is "sizeof(long)". Just multiply that by
the amount of variables, and you get how much memory they require
(assuming that they are actually used for something.)

It's a funny thing, memory, isn't it? You allocate an array of five
thousand longs, *and* write code to use it, and suddenly the process
memory grows by more than 5000*sizeof(long). Is it linear? Is it
logarithmic?... Somebody might want to find the pattern, *assuming*
there is one. And then they might want to try to figure out the
reason... They fancy themselves a researcher, so let them. Perhaps
it's in vain to try to tell them not to do it because there is some
theoretical dependency between the number of longs allocated and the
amount of memory used. So? They probably want empirical evidence.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top