C++ primer温习第二章

//c++第二章1.1-3.2

//1)变量名的命名

//c++名称的长度没有限制,所有字符都有意义,可以用下划线或者大写字母隔开eeg:my_book_list  or  myBookList

//_xx,__xx,_X,被保留给实现使用

//2)数据类型

//【整型】基本整型10种:char -> short -> int -> long -> long long (画unsinged ,有符号)

//short至少16位,int至少与short一样长,long至少32位,long long h至少64位

//CHAR_BIT,INT_MAX等表示符号常量被定义在climits文件中

//最好将变量的声明和赋值分开

//usinged是usinged int的缩写

#include <iostream>

#include <climits>

int main()

{

    // insert code here...

    using namespace std;

    int n_int = INT_MAX;

    short n_short = SHRT_MAX;

    long n_long = LONG_MAX;

    long long n_llong = LLONG_MAX;

    //cout

    cout << "int is " << sizeof(int) << "bytes. " << endl;//对类型名使用sizeof 使用运算符,必须括号

    cout << "short is "<< sizeof(n_short) << "bytes. "<< endl;//对变量名使用sizeof 预算符

    cout << "long is " << sizeof(n_long) << "bytes. "<< endl;

    cout << "long long  is "<< sizeof n_llong<< "bytes. "<< endl;对变量名使用sizeof 预算符,括号可有可无

    cout << endl;

    

    cout << "Maximum value: "<<endl;

    cout << "int: "<<n_int <<endl;

    cout << "short: "<< n_short << endl;

    cout << "long: "<< n_long << endl;

    cout <<"long long : "<<n_llong <<endl;

    cout <<"minimum value= "<< INT_MIN << endl;

    cout <<"Bits per byte = "<<CHAR_BIT <<endl;

    cout <<endl;

    

    int emus{7};

    int rheas = {12};

    int test = {};

    cout <<"emus = " << emus <<endl;

    cout << "rheas = "<< rheas <<endl;

    cout << "test = "<< test <<endl;

    

    char ch = 'M';

    int  i=ch;//i的类型确定了

    cout << "add ASCII code for" <<ch <<"  is "<<i <<endl;

    cout << "add one to the character code: "<<endl;

    ch = ch+1;

    i=ch;

    cout <<"The ASCII code for "<<ch << "is" <<i <<endl;

    cout << "desplay char ch using cout.put(ch): ";

    cout.put(ch);//函数显示一个字符

    cout.put('!');

    cout<< endl<<"Done"<<endl;

    

    cout << "ben \"Buggsie\" Hacker\nwas here!\n";

    std::cout << "Hello, World!\n";

    return 0;

}

int is 4bytes.

short is 2bytes.

long is 8bytes.

long long  is 8bytes.

 

Maximum value:

int: 2147483647

short: 32767

long: 9223372036854775807

long long : 9223372036854775807

minimum value= -2147483648

Bits per byte = 8

实验结果:

emus = 7

rheas = 12

test = 0

add ASCII code forM  is 77

add one to the character code:

The ASCII code for Nis78

desplay char ch using cout.put(ch): N!

Done

ben "Buggsie" Hacker

was here!

Hello, World!

Program ended with exit code:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值