Needed in C++ please. Write a program to determine the addresses of memory locat
ID: 3742527 • Letter: N
Question
Needed in C++ please.
Write a program to determine the addresses of memory locations allocated to various variables as follow: a. b. Declare two short int variables, two int variables, and two long int variables and then output the address of each variable. Calculate the size of the memory location allocated to each type by subtracting the address of the first variable from the address of the second variable of the same type. Repeat the problem above but with two float variables, two double variables and two long double variables (including a and b sections)Explanation / Answer
If you have any doubts, please give me comment...
#include<iostream>
using namespace std;
int main(){
short int v_s1, v_s2;
int v_i1, v_i2;
long int v_l1, v_l2;
float v_f1, v_f2;
double v_d1, v_d2;
cout<<"Short int Var1: "<<&v_s1<<endl;
cout<<"Short int Var2: "<<&v_s2<<endl;
cout<<"Int Var1: "<<&v_i1<<endl;
cout<<"Int Var2: "<<&v_i2<<endl;
cout<<"Long int Var1: "<<&v_l1<<endl;
cout<<"Long int Var2: "<<&v_l2<<endl;
cout<<"Float Var1: "<<&v_f1<<endl;
cout<<"Float Var2: "<<&v_f2<<endl;
cout<<"Double Var1: "<<&v_d1<<endl;
cout<<"Double Var2: "<<&v_d2<<endl;
cout<<endl<<endl;
cout<<"Size of Short Int:"<<(&v_s2- &v_s1)<<endl;
cout<<"Size of Int :"<<(&v_i2- &v_i1)<<endl;
cout<<"Size of Long Int :"<<(&v_l2- &v_l1)<<endl;
cout<<"Size of float :"<<(&v_f2- &v_f1)<<endl;
cout<<"Size of double :"<<(&v_d2- &v_d1)<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.