Code:
#include<iostream>
using namespace std;
int X = 123 ;
float Y = 456.7f ;
double Z = 9876.54321;
void D( int N )
{
int d = 4444 ;
cout << "d" <<" "<< d <<" "<< sizeof(d) <<" " << &d << endl;
cout << "N" <<" "<< N <<" "<< sizeof(N) <<" " << &N << endl;
}
void C( int N )
{
int c = 4444 ;
D( N ) ;
cout << "c" <<" "<< c <<" "<< sizeof(c) <<" " << &c << endl;
cout << "N" <<" "<< N <<" "<< sizeof(N) <<" " << &N << endl;
}
void B( int N )
{
int b = 4444 ;
C( N ) ;
cout << "b" <<" "<< b <<" "<< sizeof(b) <<" " << &b << endl;
cout << "N" <<" "<< N <<" "<< sizeof(N) <<" " << &N << endl;
}
void A( int N )
{
int a = 4444 ;
B( N ) ;
cout << "a" <<" "<< a <<" "<< sizeof(a) <<" " << &a << endl;
cout << "N" <<" "<< N <<" "<< sizeof(N) <<" " << &N << endl;
}
int main( )
{
cout << "variable, contents, size, adress: " << endl;
A( 12 ) ;
int *p, *q, *r, *s, *t, *u ;
p = new int ;
q = new int ;
r = new int ;
s = new int ;
t = new int ;
u = new int ;
cout << "X" <<" "<< X <<" "<< sizeof(X) <<" " << &X << endl;
cout << "Y" <<" "<< Y <<" "<< sizeof(Y) <<" " << &Y << endl;
cout << "Z" <<" "<< Z <<" "<< sizeof(Z) <<" " << &Z << endl;
cout << "*p" <<" "<< *p <<" "<< sizeof(*p) <<" " << &p << endl;
cout << "*q" <<" "<< *q <<" "<< sizeof(*q) <<" " << &q << endl;
cout << "*r" <<" "<< *r <<" "<< sizeof(*r) <<" " << &r << endl;
cout << "*s" <<" "<< *s <<" "<< sizeof(*s) <<" " << &s << endl;
cout << "*t" <<" "<< *t <<" "<< sizeof(*t) <<" " << &t << endl;
cout << "*u" <<" "<< *u <<" "<< sizeof(*u) <<" " << &u << endl;
return 0;
}
outputs:
Code:
variable, contents, size, adress:
d 4444 4 0012FDE0
N 12 4 0012FDEC
c 4444 4 0012FE3C
N 12 4 0012FE48
b 4444 4 0012FE98
N 12 4 0012FEA4
a 4444 4 0012FEF4
N 12 4 0012FF00
X 123 4 00476DC0
Y 456.7 4 00476DC4
Z 9876.54 8 00476DC8
*p -842150451 4 0012FF7C
*q -842150451 4 0012FF78
*r -842150451 4 0012FF74
*s -842150451 4 0012FF70
*t -842150451 4 0012FF6C
*u -842150451 4 0012FF68
so lets recap: I had to display each variable, contents, size and adress, donce (i think). When outputtin the contents of my pointers i get -842150451, now is this an illegal content because it doesnt point at anything?
Using the above info, i have to draw a map of the memory:
where does the static memory start and end, and does it climb or desend in terms of location im gunna assume, same for systeme stack, dynamic heap and dymanic memory, and i have to determine the total size of the dynamic memory and static memory. If its impossible, is their a way to estimate about the values?
Thanks guys, big help there!