zoukankan      html  css  js  c++  java
  • 变量的定义,强制类型转换

    类型 变量名 { }; 或者 类型 变量名 = { };

    使用List Initialization (列表初始化)的好处,高精度变低精度,会提示错误。

        int x1{ 1.123 };//提示错误
        //int x1 = 1.123;//不提示错误,x1=1

    常见类型写法如下:

        int x{};//int x=0;
        int y{ 10 };
        char c{ 'a' };
        int arr[]{1, 2, 3};//int arr[]={1,2,3};
        char s[]{"hello"};

    强制类型转换:static_cast<type> (value)

        cout << static_cast<int> (2.5);
        cout << static_cast<double>(2);
  • 相关阅读:
    codeforces
    hdu
    hdu
    poj 2823
    hdu
    hdu
    hdu
    微信公众号 SDK
    PHP 正则表达式
    注册和登录时的验证码
  • 原文地址:https://www.cnblogs.com/xixixing/p/12030601.html
Copyright © 2011-2022 走看看