標題:
[隋堂練習] Sizeof 練習運用
[打印本頁]
作者:
周政輝
時間:
2016-8-6 11:26
標題:
[隋堂練習] Sizeof 練習運用
透過Sizeof函數運用
取得每一個型態所佔的記憶體大小
Ex: sizeof(int), sizeof(string)
並透過sizeof() 取得陣列大小
[attach]1681[/attach]
作者:
蔡季樺
時間:
2016-8-6 11:38
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a[]={1,2,3,4,5,6,7,8,9,0};
cout<<"int:"<<sizeof(int)<<endl;
cout<<"string:"<<sizeof(string)<<endl;
cout<<"char:"<<sizeof(char)<<endl;
cout<<"float:"<<sizeof(float)<<endl;
cout<<"double:"<<sizeof(int)<<endl;
cout<<"陣列記憶體大小:"<<sizeof(a)<<endl;
cout<<"int:"<<sizeof(int)<<endl;
cout<<"陣列總長度:"<<sizeof(a)/sizeof(int);
for(int i=0;i<sizeof(a)/sizeof(int);i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張健勳
時間:
2016-8-6 11:40
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"Sizeof練習"<<endl;
cout<<"================="<<endl;
cout<<"int:\t"<<sizeof(int)<<endl;
cout<<"string:\t"<<sizeof(string)<<endl;
cout<<"char:\t"<<sizeof(char)<<endl;
cout<<"float:\t"<<sizeof(float)<<endl;
cout<<"double:\t"<<sizeof(double)<<endl;
int a[]={1,2,3,4,5,6,7,8,9,0};
cout<<"陣列記憶體大小:\t"<<sizeof(a)<<endl;
cout<<"int:\t"<<sizeof(int)<<endl;
cout<<"陣列總長度為:\t"<< sizeof(a) / sizeof(int) <<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡庭豪
時間:
2016-8-6 11:52
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
int x[]={1,2,3,4,5,6,7,8,9,0};
cout<<"int:"<<sizeof(int)<<endl;
cout<<"string:"<<sizeof(string)<<endl;
cout<<"char:"<<sizeof(char)<<endl;
cout<<"float:"<<sizeof(float)<<endl;
cout<<"double:"<<sizeof(double)<<endl;
cout<<"陣列記憶體大小:"<<sizeof(x)<<endl;
cout<<"int:"<<sizeof(int)<<endl;
cout<<"陣列總長度"<<sizeof(x)/sizeof(int)<<endl;
for(int i=0;i<sizeof(x)/sizeof(int);i++){
cout<<x[i]<<",";
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2