/*
6. Modify YourPets2.cpp so that it uses various different
data types (char, int, float, double, and their variants).
Run the program and create a map of the resulting
memory layout. If you have access to more than one kind
of machine, operating system, or compiler, try this
experiment with as many variations as you can manage.
*/
#include < iostream >
using namespace std;
int dog, cat, bird, fish;
void f( int pet) {
cout << " pet id number: " << pet << endl;
}
int main() {
int i, j, k;
cout << " f(): " << ( long ) & f << endl;
cout << " dog: " << ( long ) & dog << endl;
cout << " cat: " << ( long ) & cat << endl;
cout << " bird: " << ( long ) & bird << endl;
cout << " fish: " << ( long ) & fish << endl;
cout << " i: " << ( long ) & i << endl;
cout << " j: " << ( long ) & j << endl;
cout << " k: " << ( long ) & k << endl;
} /// :~
data types (char, int, float, double, and their variants).
Run the program and create a map of the resulting
memory layout. If you have access to more than one kind
of machine, operating system, or compiler, try this
experiment with as many variations as you can manage.
*/
#include < iostream >
using namespace std;
int dog, cat, bird, fish;
void f( int pet) {
cout << " pet id number: " << pet << endl;
}
int main() {
int i, j, k;
cout << " f(): " << ( long ) & f << endl;
cout << " dog: " << ( long ) & dog << endl;
cout << " cat: " << ( long ) & cat << endl;
cout << " bird: " << ( long ) & bird << endl;
cout << " fish: " << ( long ) & fish << endl;
cout << " i: " << ( long ) & i << endl;
cout << " j: " << ( long ) & j << endl;
cout << " k: " << ( long ) & k << endl;
} /// :~
本文通过修改YourPets2.cpp程序,展示了如何使用多种数据类型(如char、int、float、double等),并运行程序来创建内存布局地图。实验旨在观察不同机器、操作系统或编译器下变量地址的变化。

9111

被折叠的 条评论
为什么被折叠?



