zoukankan      html  css  js  c++  java
  • 练习2.10:下面变量的初始值是什么?

    练习2.10:下面变量的初始值是什么?

     1 #include<iostream>
     2 #include<Windows.h>
     3 
     4 using namespace std;
     5 
     6 
     7 std::string g_str;
     8 int g_int;
     9 
    10 int main(void)
    11 {
    12     int local_int;
    13     std::string loca_str;
    14 
    15     cout << "g_str" << g_str <<endl;
    16     cout << "g_int" << g_int<<endl;
    17     cout << "loca_str" << loca_str << endl;
    18 
    19     cout << "local_int" << local_int <<endl;
    20     system("pause");
    21     return 0;
    22 }

    答案:

    第19行报error

    其余结果为:

    g_str###
    g_int0###
    loca_str###

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    总结:

    字符串默认初始化为空。局部整型变量不初始化会报错。

  • 相关阅读:
    Linux
    Linus
    Linux
    Linux
    Linux
    Linux
    Linux
    Linux
    Django日志配置
    linux
  • 原文地址:https://www.cnblogs.com/tito/p/12358605.html
Copyright © 2011-2022 走看看