zoukankan      html  css  js  c++  java
  • C++课堂练习二

    1、数据类型及其所占字节数

    #include<iostream>
    #include<string>
    using namespace std;
    
    int main(){
        cout << "***************************************" << endl;
        cout << "int:"<< sizeof(int) << endl; 
        cout << "short int:"<< sizeof(short int) << endl;
        cout << "long int:"<< sizeof(int) << endl; 
        cout << "unsigned int:"<< sizeof(unsigned int) << endl;
        cout << "unsigned short int:"<< sizeof(unsigned short int) << endl;
        cout << "unsigned long int:"<< sizeof(unsigned long int) << endl;  
        cout << "char:"<< sizeof(char) << endl;
        cout << "unsigned char:"<< sizeof(unsigned char) << endl;
        cout << "bool:"<< sizeof(bool) << endl;
        cout << "double:"<< sizeof(double) << endl;  
        cout << "float:"<< sizeof(float) << endl;
        cout << "***************************************" << endl;
        cout << "A:" << sizeof('A') << endl;
        cout << "1:" << sizeof(1) << endl;
        cout << "1.0:" << sizeof(1.0) << endl;
        cout << "True:" << sizeof(true) << endl;
        cout << "hello World:" << sizeof("Hello World") << endl;
        cout << "程序:" << sizeof("程序") << endl;
        cout << "***************************************" << endl;
        return 0;
    } 

    #include<iostream>
    #include<string>
    #include<limits> 
    using namespace std;
    
    int main(){
        cout << "int			所占字节数:" << sizeof(int)<< "		min:" << (numeric_limits<int>::min)() << "		max:" << (numeric_limits<int>::max)()<< endl;
        cout << "short int		所占字节数:" << sizeof(short int)<< "		min:" << (numeric_limits<short int>::min)() << "		max:" << (numeric_limits<short int>::max)()<< endl;
        cout << "long int		所占字节数:" << sizeof(long int) << "		min:" << (numeric_limits<long int>::min)() << "		max:" << (numeric_limits<long int>::max)()<< endl;
        cout << "unsigned int		所占字节数:" << sizeof(unsigned int)<< "		min:" << (numeric_limits<unsigned int>::min)() << "			max:" << (numeric_limits<unsigned int>::max)()<< endl;
        cout << "unsigned short int	所占字节数:" << sizeof(unsigned short int)<< "		min:" << (numeric_limits<unsigned short int>::min)() << "			max:" << (numeric_limits<unsigned short int>::max)()<< endl;
        cout << "unsigned long int	所占字节数:" << sizeof(unsigned long int)<< "		min:" << (numeric_limits<unsigned long int>::min)() << "			max:" << (numeric_limits<unsigned long int>::max)()<< endl;
        cout << "char			所占字节数:" << sizeof(char) << "		min:" << (numeric_limits<char>::min)() << "			max:" << (numeric_limits<char>::max)()<< endl;
        cout << "signed char		所占字节数:" << sizeof(signed char)<< "		min:" << (numeric_limits<signed char>::min)() << "			max:" << (numeric_limits<signed char>::max)()<< endl;
        cout << "unsigned char		所占字节数:" << sizeof(unsigned char)<< "		min:" << (numeric_limits<unsigned char>::min)() << "			max:" << (numeric_limits<unsigned char>::max)()<< endl;
        cout << "bool			所占字节数:" << sizeof(bool)<< "		min:" << (numeric_limits<bool>::min)() << "			max:" << (numeric_limits<bool>::max)()<< endl;
        cout << "string			所占字节数:" << sizeof(string)<< "		min:" << (numeric_limits<string>::min)() << "			max:" << (numeric_limits<string>::max)()<< endl;
        cout << "double			所占字节数:" << sizeof(double)<< "		min:" << (numeric_limits<double>::min)() << "	max:" << (numeric_limits<double>::max)()<< endl;
        cout << "float			所占字节数:" << sizeof(float)<< "		min:" << (numeric_limits<float>::min)() << "	max:" << (numeric_limits<float>::max)()<< endl;
        return 0;
    } 

  • 相关阅读:
    2014025640《嵌入式程序设计》第二周学习总结
    基于Struts2的SpringMVC入门
    2014025640《嵌入式设计》第一周学习总结
    Hadoop综合大作业
    hive基本操作与应用
    用mapreduce 处理气象数据集
    熟悉常用的HBase操作,编写MapReduce作业
    爬虫大作业
    熟悉常用的HDFS操作
    中文词频统计
  • 原文地址:https://www.cnblogs.com/liqing45/p/11451161.html
Copyright © 2011-2022 走看看