C++ 未初始化的類成員變量

未初始化的類成員變量

 

在gcc 4.8.5版本

如果還有未初始化的類成員變量,其值不確定

#include <iostream>

class T {
    public:
        T() {}

    float tt;
    int it;
};


int main() {
    float ff;
    cout << ff << endl;

    T t1;
    cout << t1.tt << endl;
    cout << t1.it << endl;

    return 0;
}

結果

[root@mx xsp2]# ./a.out
0
-17304.5
32766
[root@mx xsp2]# ./a.out
0
1.78996e+11
32767
[root@mx xsp2]# ./a.out
0
2.91494e-38
32766
[root@mx xsp2]# ./a.out
0
9.19502e+18
32767
[root@mx xsp2]# ./a.out
0
-3.06696e-30
32767
[root@mx xsp2]# ./a.out
0
-78.9587
32764

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章