久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      c++數(shù)組初始化的種類有哪些

      c++數(shù)組初始化的種類有:1、整型數(shù)組的初始化;2、字符串的初始化;3、數(shù)組的默認初始化;4、數(shù)組的堆初始化。

      c++數(shù)組初始化的種類有哪些

      c++數(shù)組初始化的種類有:

      1、整型數(shù)組的初始化-棧初始化

      //默認初始化 int a[5] = {};    //[0, 0, 0, 0, 0] //全部初始化為0 int a[5] = {0};    //[0, 0, 0, 0, 0] //c++11新寫法 int a[5]{};    //[0, 0, 0, 0, 0] //注意,想要整型數(shù)組 全部初始化為1的時候不能粗暴的設置為  int a[5] = {1};    //[1, 0, 0, 0, 0] // 因為 數(shù)組初始化列表中的元素個數(shù)小于指定的數(shù)組長度時, 不足的元素以默認值填補。 //可以分別賦值 int a[5] = {1,1,1,1,1}; //[1,1,1,1,1]

      2、字符串的初始化-棧初始化

      和整型的初始化基本一致,會調用構造函數(shù)

      string *str = string[5];    //調用5次默認構造函數(shù) string *str1 = string[5]{"aaa"};    //數(shù)組中的第一個元素調用 string::string(const char *)  進行初始化。后面四個調用 默認構造函數(shù)

      3、數(shù)組的默認初始化

      如果不明確指出初始化列表,那么基本類型不會被初始化(全局變量和靜態(tài)變量除外),所有內存都是臟數(shù)據(jù);且自定義的類類型會為每個元素調用默認構造函數(shù)進行初始化

      int a[5]{}; a[6];      //32766 a[10];    //1474921429 // Xcode會提示 Array index 10 is past the end of the array (which contains 5 elements)。雖然不會爆紅,但是Xcode提示越界了。這在程序中也是需要特別注意的,越界時會取到臟數(shù)據(jù)。 string str[5];     //["","","","",""] string str1[5] = {"","2","",""};     //["","2","',"",""] string str2[5] = {"a"};     //["a","","","",""]

      4、數(shù)組的堆初始化

      int *a = new int[5];        //臟數(shù)據(jù)數(shù)組 int *str = new string[5];    //空字符串數(shù)組 int *b = new int[5]{0};    //   [0,0,0,0,0] int *str1 = new string[5] {"aaa"};    //["aaa","","","",""] //以上幾行代碼遵循棧中數(shù)組的初始化規(guī)則,除此之外這里還有一個新語法 int *c = new int[5]();    //[0,0,0,0,0] //該語法后面的一對圓括號,表示使用默認值初始化整個數(shù)組,所以對于類類型來說,new string[5] 與 new string[5]() 是等價的,都會調用默認構造函數(shù)進行初始化;但是對于基本類型就不同了。new int[5]根本不會初始化,而new int[5]()則會使用int()的值,即0進行初始化。

      【相關學習推薦:C語言教程視頻】

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號