Character data and integer data

Character data can store single-byte characters, such as ASCII code, and the data in memory at this time is the ASCII code value of the character. For example, the storage form of the character 'A' in memory is 0100001, which is the asc || code value of 'A'.
In C ++ language, character data and integer data can be used in common . A character data can be assigned to an integer variable, an integer data can also be assigned to a character variable, and arithmetic operations can be performed on the character data.

在这里插入代码片
#include <iostream>
using namespace std;
int main()
{
    int i, j;
    char c1, c2;
    c1 = 'a'; //字符数据赋值给字符型
    c2 = 98;  //整数数据赋值给字符型
    i = 'A';  //字符数据赋值给整型
    j = 66;   //整数数据赋值给整型
    cout << "i=" << i << ",j=" << j << ",c1=" << c1 << ",c2=" << c2 << endl;
    cout << "c1-32=" << c1 - 32 << endl; //字符型可以进行减法运算
    return 0;
}

Running result
i = 65, j = 66, c1 = a, c2 = b
c1-32 = 33

Published 19 original articles · Like9 · Visits 2900

Guess you like

Origin blog.csdn.net/u013031697/article/details/104520764