• (C/C++学习笔记) 七. 类型转换


    七. 类型转换

    ● 隐式类型转换

    隐式类型转换 implicit type conversions

    #include<iostream>

    using namespace std;

    void main()

    {

        double result;

        char a='k';            //kASCII码为107

        int b=10;

        float e=1.515;

        result=(a+b)-e;        //char转换为int,然后int转换为float

        printf("%f ",result);

    }

     

     

    ● 显式类型转换

    显式类型转换explicit type conversion

    #include<iostream.h>

     

    int main()

    {

        float z=7.56, fractionPart;

        int integerPart;

        integerPart=int(z);

        fractionPart=z-(int)z;

        cout<<integerPart<<endl;

        cout<<fractionPart<<endl;

        return 0;

    }

     

    type_name (expression)        //C++ cast notation

    (type_name) expression        //C cast notation

     

    An expression consists of a combination of operators and operands. (An operand is what an operator operates on.) The simplest expression is a lone operand, and you can build in complexity from there. E.g.:

    4

    -6

    4+21

    a*(b + c/d)/20

    q = 5*2

    x = ++q % 3

    q > 3

     

  • 相关阅读:
    linux开发基本库
    Configure,Makefile.am, Makefile.in, Makefile文件
    sql的其他语句
    sql 链接 查询
    sql的 select
    SQL语句:
    angular 指令系统(二)自定义指令:
    angularJS 指令系统
    angular JS 过滤器
    angularJS 控制器
  • 原文地址:https://www.cnblogs.com/ArrozZhu/p/8377714.html
Copyright © 2020-2023  润新知