基本数据类型程序
Fundamental Data Types Program
我写了以下代码:
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
char c;
int i;
short int j;
long int k;
float f;
double d;
long double e;
cout << "The size of char is: " << sizeof c << endl;
cout << "The size of int is: " << sizeof i << endl;
cout << "The size of short int is: " << sizeof j << endl;
cout << "The size of long int is: " << sizeof k << endl;
cout << "The size of float is: " << sizeof f << endl;
cout << "The size of double is: " << sizeof d << endl;
cout << "The size of long double is: " << sizeof e << endl;
system("pause");
return 0;
}
这个程序的目的是打印出基本数据类型的大小,我认为我已经完成了。这个程序的另一个目的是输出指向这些数据类型的指针的大小。我不知道该怎么做。我知道指针是存储另一个变量的地址的变量,指针涉及到差分操作符(*)。谁能提个建议?我不是在寻找答案,只是在正确的方向上轻轻一推。
int *p; // p is a pointer to an int
所以指针的sizeof是:sizeof p
,可以打印为:
cout << "The size of int pointer is: " << sizeof p << endl;
这是你需要做的打印其他指针的大小
解引用仅在想要访问指针所指向的对象时才执行。例如
int i = 5;
int *p = &i;
*p = 6;
*p = *p + 1;
//etc
这里,你只想得到指针的大小。因此不需要解引用
相关文章:
- 防止主数据类型C++的隐式转换
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 在C++中打印指向不同基元数据类型的指针的内存地址
- C++浮点数据类型和字符串数据类型无法子到模板函数中
- 如何在不破坏现有应用程序的情况下更改 API 中 stl 容器的数据类型?
- 使用MPI/OpenMP的C 程序带有派生数据类型(嵌套类对象)容器
- 如何制作一个为程序的每个运行中存储不同数据类型的向量
- 如何检查程序是否超过数据类型存储
- wxWidgets 应用程序中的 SOCI 数据类型
- 窗口后台处理程序究竟如何确定它将发送到打印处理器的数据类型?
- 如何使用 C++ 驱动程序在 MongoDB 中使用 UserException 处理数据类型错误
- c++hdf5:如何设计易于扩展到新的复合数据类型的程序
- 将值分配给Float数据类型崩溃程序
- 在 C 程序中存储"binary"数据类型
- 如果应用程序仅针对 armv7 和 armv7 编译,则在 arm64 设备上运行时,它使用什么大小的数据类型
- 有必要在为Windows和Linux编写的程序中处理长数据类型吗
- 在c++程序中,哪种数据类型不能作为异常抛出
- BOOLEAN数据类型程序代码
- 基本数据类型程序
- 在托管c#应用程序的非托管c++ Dll调用中,如何处理数据类型之间的冲突