this is my profs code, plz dont slam me for itCode:#include<iostream.h>
int X = 123 ;
float Y = 456.7f ;
double Z = 9876.54321;
void D( int N )
{
int d = 4444 ;
}
void C( int N )
{
int c = 4444 ;
D( N ) ;
}
void B( int N )
{
int b = 4444 ;
C( N ) ;
}
void A( int N )
{
int a = 4444 ;
B( N ) ;
}
void main( )
{
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 ;
}
I have to display the size of each variable, and its adress and the contents of each variable , i have to find the static memory, find the starting adress of the pile (dynamic memory) and the sytarting adress of the heap, and the size of the dynamic and static memory.
Prof explains dick ........, and i dont understand much on pointers so any tips, hints, help, tricks, etc, is more the appretiated.
this is what i have to date
does that look right to show each variable, contents and adress?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;
return 0;
}
I also have to do the same for the pointers (p, r, q, etc)
I also need to identify where the static memory is at, the staring adress for the pile (dymic memory) and identify the starting adress of the heap (dynamic memory)^
if i add this line of code, i get the adress of the pointer, its size (4, int, checks out), and content some weird useless number since its searching for somthing that doesnt exist, so is it all good??Code:cout << "*p" <<" "<< *p <<" "<< sizeof(*p) <<" " << &p << endl;