1. 程式人生 > >c++中的char型別簡單分析

c++中的char型別簡單分析

#include <iostream>
using namespace std;
int main()
{

    char aa='123';//直接定義char輸出是最後一個字元,還有字元最後一個字元是“n/”
    char a='qd';
    char f []="zxc"; //定義陣列型別的char  ,f[0]是第一個,從0開始
    char *p=f;//指標型別的直接輸出全部字元

    cout<<p<<endl;
    cout <<f<<endl;
    cout <<f[2]<<endl;
    cout <<a<<endl;
    cout <<aa<<endl;
    printf("%d",aa);
    printf("%c",aa);
    return 0;
}

結果:

zxc
zxc
c
d
3
513

再來一個例子:

#include <iostream>
using namespace std;
int main()
{
    char aa='A';
    printf("%d",aa);
    printf("%c",aa);
    return 0;
}

65A

這說明d形式是ascll形式。