我寫了下面的代碼:基本數據類型程序
#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;
}
這項計劃的目的是打印出來的基本數據類型,我認爲我已經完成的大小。這個程序的另一個目的是打印指向這些數據類型的指針的大小。我很難弄清楚如何做到這一點。我知道一個指針是一個變量,它存儲另一個變量的地址,並且這個指針包含了參數操作符(*)。任何人都可以提供一個建議嗎?我不是在尋找答案,只是在正確的方向推動。
例如, '的sizeof(K)'?順便說一句,我認爲你會發現這個答案有點無聊;) – U2EF1