简体   繁体   中英

If char can store a number in C++, why do we need int?

The char data type can store numbers, characters, and symbols, so what is the need for the int data type?

char = '2';

I have knowledge of use of int , but I want to know the conceptual part to describe it fundamentally.

Usually, int can hold larger numbers than char . In current, widely available architectures, int is 32-bit, while char is 8-bit. Furthermore, it is implementation defined that a char is signed or unsigned.

On these architectures int can hold numbers between -2147483648 and 2147483647, while a (signed) char can hold numbers between -128 and 127.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM