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;
    } 

  • 相关阅读:
    HDU2059(龟兔赛跑)
    pat 1012 The Best Rank
    pat 1010 Radix
    pat 1007 Maximum Subsequence Sum
    pat 1005 Sign In and Sign Out
    pat 1005 Spell It Right
    pat 1004 Counting Leaves
    1003 Emergency
    第7章 输入/输出系统
    第六章 总线
  • 原文地址:https://www.cnblogs.com/liqing45/p/11451161.html
Copyright © 2011-2022 走看看