返回列表 發帖

指標 (一) - 位址運算符號

本帖最後由 tonyh 於 2014-8-30 17:58 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int intVar=10;
  7.      float floatVar=3.14f;
  8.      double doubleVar=3.14159;
  9.      long double longdVar=1.276e+3000;
  10.      string strVar1="我是字串";
  11.      char strVar2[13]="我是字元陣列";
  12.      cout<<"變數名稱\t變數位址\t所占空間"<<endl;
  13.      cout<<"-------------------------------------------"<<endl;
  14.      cout<<"intVar   \t"<<&intVar<<"\t"<<sizeof(intVar)<<"位元組"<<endl;
  15.      cout<<"floatVar \t"<<&floatVar<<"\t"<<sizeof(floatVar)<<"位元組"<<endl;
  16.      cout<<"doubleVar\t"<<&doubleVar<<"\t"<<sizeof(doubleVar)<<"位元組"<<endl;
  17.      cout<<"longdVar \t"<<&longdVar<<"\t"<<sizeof(longdVar)<<"位元組"<<endl;
  18.      cout<<"strVar1  \t"<<&strVar1<<"\t"<<sizeof(strVar1)<<"位元組"<<endl;
  19.      cout<<"strVar2  \t"<<&strVar2<<"\t"<<sizeof(strVar2)<<"位元組"<<endl;
  20.      system("pause");
  21.      return 0;
  22. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int intVar=10;
  7.      float floatVar=3.14f;
  8.      double doubleVar=3.14159;
  9.      long double longdVar=1.276e+3000;
  10.      string strVar1="我是字串";
  11.      char strVar2[13]="我是字元陣列";
  12.      cout<<"變數名稱\t變數位址\t所占空間"<<endl;
  13.      cout<<"-------------------------------------------"<<endl;
  14.      cout<<"intVar   \t"<<&intVar<<"\t"<<sizeof(intVar)<<"位元組"<<endl;
  15.      cout<<"floatVar \t"<<&floatVar<<"\t"<<sizeof(floatVar)<<"位元組"<<endl;
  16.      cout<<"doubleVar\t"<<&doubleVar<<"\t"<<sizeof(doubleVar)<<"位元組"<<endl;
  17.      cout<<"longdVar \t"<<&longdVar<<"\t"<<sizeof(longdVar)<<"位元組"<<endl;
  18.      cout<<"strVar1  \t"<<&strVar1<<"\t"<<sizeof(strVar1)<<"位元組"<<endl;
  19.      cout<<"strVar2  \t"<<&strVar2<<"\t"<<sizeof(strVar2)<<"位元組"<<endl;
  20.      system("pause");
  21.      return 0;
  22. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;

  5. int main()
  6. {
  7.     int intVar=10;
  8.     float floatVar=3.14f;
  9.     double doubleVar=3.14;
  10.     long double longdVar=5e+2;
  11.     string strVar1="aaaaa";
  12.     char strVar2[13]="aaaaaaaaaaaa";
  13.     cout<<"變數名稱\t變數位址\t所占空間\n";
  14.     cout<<"----------------------------------------\n";
  15.     cout<<"intVar   \t"<<&intVar<<'\t'<<sizeof(intVar)<<" bytes\n";
  16.     cout<<"floatVar \t"<<&floatVar<<'\t'<<sizeof(floatVar)<<" bytes\n";
  17.     cout<<"doubleVar\t"<<&doubleVar<<'\t'<<sizeof(doubleVar)<<" bytes\n";
  18.     cout<<"longdVar \t"<<&longdVar<<'\t'<<sizeof(longdVar)<<" bytes\n";
  19.     cout<<"strVar1  \t"<<&strVar1<<'\t'<<sizeof(strVar1)<<" bytes\n";
  20.     cout<<"strVar2  \t"<<&strVar2<<'\t'<<sizeof(strVar2)<<" bytes\n";
  21.     system("pause");
  22.     return 0;
  23. }
  24.    
  25.    
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int intVar=10;
  7.      float floatVar=3.14f;
  8.      double doubleVar=3.14159;
  9.      long double longdVar=1.276e+3000;
  10.      string strVar1="我是字串";
  11.      char strVar2[13]="我是字元陣列";
  12.      cout<<"變數名稱\t變數位址\t所占空間"<<endl;
  13.      cout<<"-------------------------------------------"<<endl;
  14.      cout<<"intVar   \t"<<&intVar<<"\t"<<sizeof(intVar)<<"位元組"<<endl;
  15.      cout<<"floatVar \t"<<&floatVar<<"\t"<<sizeof(floatVar)<<"位元組"<<endl;
  16.      cout<<"doubleVar\t"<<&doubleVar<<"\t"<<sizeof(doubleVar)<<"位元組"<<endl;
  17.      cout<<"longdVar \t"<<&longdVar<<"\t"<<sizeof(longdVar)<<"位元組"<<endl;
  18.      cout<<"strVar1  \t"<<&strVar1<<"\t"<<sizeof(strVar1)<<"位元組"<<endl;
  19.      cout<<"strVar2  \t"<<&strVar2<<"\t"<<sizeof(strVar2)<<"位元組"<<endl;
  20.      system("pause");
  21.      return 0;
  22. }  
複製代碼

TOP

本帖最後由 周雍程 於 2014-9-13 11:50 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int intVar=10;
  7.      float floatVar=3.14f;
  8.      double doubleVar=3.14159;
  9.      long double longdVar=1.276e+3000;
  10.      string strVar1="我是字串";
  11.      char strVar2[13]="我是字元陣列";
  12.      cout<<"變數名稱\t變數位址\t所占空間"<<endl;
  13.      cout<<"-------------------------------------------"<<endl;
  14.      cout<<"intVar   \t"<<&intVar<<"\t"<<sizeof(intVar)<<"位元組"<<endl;
  15.      cout<<"floatVar \t"<<&floatVar<<"\t"<<sizeof(floatVar)<<"位元組"<<endl;
  16.      cout<<"doubleVar\t"<<&doubleVar<<"\t"<<sizeof(doubleVar)<<"位元組"<<endl;
  17.      cout<<"longdVar \t"<<&longdVar<<"\t"<<sizeof(longdVar)<<"位元組"<<endl;
  18.      cout<<"strVar1  \t"<<&strVar1<<"\t"<<sizeof(strVar1)<<"位元組"<<endl;
  19.      cout<<"strVar2  \t"<<&strVar2<<"\t"<<sizeof(strVar2)<<"位元組"<<endl;
  20.      system("pause");
  21.      return 0;
  22. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int cal(int,int);
  5. int cal(int,int,int);
  6. int main()
  7. {
  8.     int intVar=10;
  9.     float floatVar=3.14f;
  10.     double doubleVar=3.14159;
  11.     long double longdVar=5.378e+300;
  12.     string strVar1="我是字串";
  13.     char strVar2[]="我是字元陣列";
  14.     cout<<"變數名稱\t變數位址\t所占空間"<<endl;  
  15.     cout<<"---------------------------------------"<<endl;
  16.     cout<<"intVar   \t"<<&intVar<<"\t"<<sizeof(intVar)<<"位元組"<<endl;
  17.     cout<<"floatVar \t"<<&floatVar<<"\t"<<sizeof(floatVar)<<"位元組"<<endl;
  18.     cout<<"doubleVar\t"<<&doubleVar<<"\t"<<sizeof(doubleVar)<<"位元組"<<endl;
  19.     cout<<"longdVar \t"<<&longdVar<<"\t"<<sizeof(longdVar)<<"位元組"<<endl;
  20.     cout<<"strVar1  \t"<<&strVar1<<"\t"<<sizeof(strVar1)<<"位元組"<<endl;
  21.     cout<<"strVar2  \t"<<&strVar2<<"\t"<<sizeof(strVar2)<<"位元組"<<endl;
  22.     system("pause");   
  23.     return 0;
  24. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     int intVar=10;
  7.     float floatVar=3.14f;
  8.     double doubleVar=3.14159;
  9.     long double longdVar=5.378e+300;
  10.     string strVar1="我識字串";
  11.     char strVar2[]="我是字元陣列";
  12.     cout<<"變數名稱\t變數位址\所佔空間"<<endl;
  13.     cout<<"-------------------------------------------"<<endl;
  14.     cout<<"inVar    \t"<<&intVar<<"\t"<<sizeof(intVar)<<"位元組"<<endl;
  15.     cout<<" floatVar\t"<<&floatVar<<"\t"<<sizeof( floatVar)<<"位元組"<<endl;
  16.     cout<<"doubleVar\t"<<&doubleVar<<"\t"<<sizeof(doubleVar)<<"位元組"<<endl;
  17.     cout<<"longdVar \t"<<&longdVar<<"\t"<<sizeof(longdVar)<<"位元組"<<endl;
  18.     cout<<"strVar1  \t"<<&strVar1<<"\t"<<sizeof(strVar1)<<"位元組"<<endl;
  19.     cout<<"strVar2  \t"<<&strVar2<<"\t"<<sizeof(strVar2)<<"位元組"<<endl;
  20.     system("pause");   
  21.     return 0;
  22. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      int intVar=10;
  7.      float floatVar=3.14f;
  8.      double doubleVar=3.14159;
  9.      long double longdVar=1.276e+3000;
  10.      string strVar1="我是字串";
  11.      char strVar2[13]="我是字元陣列";
  12.      cout<<"變數名稱\t變數位址\t所占空間"<<endl;
  13.      cout<<"-------------------------------------------"<<endl;
  14.      cout<<"intVar   \t"<<&intVar<<"\t"<<sizeof(intVar)<<"位元組"<<endl;
  15.      cout<<"floatVar   \t"<<&floatVar<<"\t"<<sizeof(floatVar)<<"位元組"<<endl;
  16.      cout<<"doubleVar   \t"<<&doubleVar<<"\t"<<sizeof(doubleVar)<<"位元組"<<endl;
  17.      cout<<"longdVar   \t"<<&longdVar<<"\t"<<sizeof(longdVar)<<"位元組"<<endl;
  18.      cout<<"strVar1   \t"<<&strVar1<<"\t"<<sizeof(strVar1)<<"位元組"<<endl;
  19.      cout<<"strVar2   \t"<<&strVar2<<"\t"<<sizeof(strVar2)<<"位元組"<<endl;
  20.      system("pause");
  21.      return 0;
  22. }
複製代碼

TOP

本帖最後由 陳品叡 於 2024-8-9 16:04 編輯
  1. #include <bits/stdc++.h>

  2. using namespace std;



  3. int main()
  4. {
  5.     int intvar = 100;
  6.     float floatvar = 0.369;
  7.     double doublevar = 12.6598;
  8.     long double longdvar = 12.369;
  9.     string strvar1 = "我是字串";
  10.     char strvar2[] = "我是字元陣列";
  11.     cout << "intvar      \t" << &intvar << "\t\t" << sizeof(intvar) << endl;
  12.     cout << "floatvar   \t" << &floatvar << "\t\t" << sizeof(floatvar) << endl;
  13.     cout << "doublevar\t" << &doublevar << "\t\t" << sizeof(doublevar) << endl;
  14.     cout << "longdvar  \t" << &longdvar << "\t\t" << sizeof(longdvar) << endl;
  15.     cout << "strvar1    \t" << &strvar1 << "\t\t" << sizeof(strvar1) << endl;
  16.     cout << "strvar2    \t" << &strvar2 << "\t\t" << sizeof(strvar2) << endl;
  17.     return 0;
  18. }
複製代碼

TOP

返回列表