数据类型

#include<iostream>
using namespace std;
#include<string>//在用c++风格字符串时候,要包含的头文件
int main()
{
    //可以用sizeof求出数据类型占用内存大小
    //: sizeof(数据类型、变量)
    short a = 10;
    cout << "short占用内存空间为:" << sizeof(a) << endl;

    int b = 10;
    cout << "int占用内存空间为:" << sizeof(b) << endl;

    long c = 10;
    cout << "long占用内存空间为:" << sizeof(c) << endl;

    long long d = 10;
    cout << "long long占用内存空间为:" << sizeof(d) << endl;
     

//单精度  float
//双精度  double
    float f = 3.14;
    cout << "f=" << f << endl;
    cout << "float占用内存空间为:" << sizeof(f) << endl;
    double g = 3.14;
    cout << "g=" << g << endl;
    cout << "float占用内存空间为:" << sizeof(g) << endl;

    char ch = 'a';
    cout << ch << endl;

    //1、C风格字符串
    //char 字符串名[]
    //等号 后面要用“”包含起字符串
    char str[] = "hello world";
    cout << str << endl;
    //2、C++风格字符串
    //包含一个头文件  #include<string>
    string str2 = "hello world";
    cout << str2 << endl;


    system("pause");
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值