c语言数据类型及其数据范围_C中的数据类型

c语言数据类型及其数据范围

In some of our tutorials in the beginning, I told you about the three primary data types which are used in C language. Today I will introduce you to some variations in these primary data types in C. We can make unlimited data types as per our requirement in C. So C language is quite rich in data types.

Data Types in C

The primary data types which we have used till now has some limits. For example, we can only store values in the range of –32768 to 32767 for an int data type. Remember this range is for 16 bit compiler Turbo C. For 32 bit compiler like VC++ this range is  –2147483648 to +2147483647. You can’t store more values which exceed this limit in int data type. To overcome those limits we have to use some extra keywords like unsigned, signed etc.

What are 16 bit and 32 bit compilers?
Turbo C is a 16 bit compiler. After converting the C code into machine language, it will target that code to run on 16 bit processors like intel 8086.

On the other hand VC++ is a 32 bit compiler. It will target to run the code on 32 bit processors like intel Pentium processors.

short and long int

As I said earlier C language provides variation in its primary data types. short and long are such variations of integer data type. As its name suggests long has bigger range than int.

Note: Here short and long are both keywords.

The range of both short and long are given below.

Range of long is -2147483648  to 2147483647.
Range of short is -32,768 to +32,767

signed and unsigned int

Generally it happened when we are confirmed that the value will not be negative in any case. So to utilize those conditions efficiently we often use unsigned int. With the use of unsigned keyword the range of int data type shifts from negative to positive.

New range will be 0 to 65535

By default normal int is also called signed int.

signed and unsigned char

Range of normal char is -128 to +127. You must have known that char data type always stores the ASCII value of character. Many times we emerge in a condition when we have print or access the ASCII character who value is more than +127. So in that case we generally use unsigned char. Similar to int it also makes the range almost twice. Both signed and unsigned char occupies 1 byte in memory.

New range will be 0 to 255

float and double

float variable occupies 4 bytes in memory and it also provides a good range to store values in it. It gives the range of -3.4e38 to +3.4e38. 

If you want to increase this limit then you can also use double data type. It takes 8 bytes in the memory and it also provided a very big range to store values. Its range is -1.7e4932 to +1.7e4932.

Declaration of all data types

Given below are declarations of all the data types which we have learned so far.

int a;
unsigned int b;
long int c;
short int d;
unsigned short int e;
unsigned long int f;
char g;
unsigned char f;
float g;
double h;

翻译自: https://www.thecrazyprogrammer.com/2015/01/data-types-in-c.html

c语言数据类型及其数据范围

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值