[THINKING IN C++]CHAPTER 03:EXERCISE 06

本文通过修改YourPets2.cpp程序,展示了如何使用多种数据类型(如char、int、float、double等),并运行程序来创建内存布局地图。实验旨在观察不同机器、操作系统或编译器下变量地址的变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/* 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)&<< endl;
  cout 
<< "dog: " << (long)&dog << endl;
  cout 
<< "cat: " << (long)&cat << endl;
  cout 
<< "bird: " << (long)&bird << endl;
  cout 
<< "fish: " << (long)&fish << endl;
  cout 
<< "i: " << (long)&<< endl;
  cout 
<< "j: " << (long)&<< endl;
  cout 
<< "k: " << (long)&<< endl;
///:~
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值