C语言中的限定符是什么?
我正在这个网址阅读一些文字:
https://cs. senecac.on.ca/~btp100/pages/content/varia_p.html
在“限定符”部分中,他们说:
“我们可以限定 int 类型以确保它包含最小位数” .... Short 至少包含 16 位: ....
我不明白这一点,“限定 int 类型”是什么意思以及为什么“A Short 至少包含 16 位”。
有人可以详细说明一下吗? 谢谢大家。
I am reading some text at this url:
https://cs.senecac.on.ca/~btp100/pages/content/varia_p.html
In the section 'Qualifiers', they say:
"We can qualify the int type to be sure that it contains a minimum number of bits"
....
A short contains at least 16 bits:
....
I don't understand this, what does "qualify the int type" mean and why "A short contains at least 16 bits".
Can anybody elaborate on this please?
Thanks all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
限定符是给变量或函数的额外名称,显示该变量或函数的额外质量或额外含义。就像 Dr Arun Kumar 中的 Dr
变量的限定符是(类型限定符):
signed
、unsigned
、long
、short
,long long
,const
,易失性
,静态
,自动
,extern
、register
函数的限定符有:
static
、extern
、inline
Qualifier is an extra name given to either variables or functions , showing an extra quality or extra meaning for that variable or function. like Dr in Dr Arun Kumar
Qualifiers for variables are (TYPE qualifiers):
signed
,unsigned
,long
,short
,long long
,const
,volatile
,static
,auto
,extern
,register
Qualifiers for functions are:
static
,extern
,inline
关键字
short
、long
、unsigned
、signed
等称为限定符。限定符的顺序无关紧要,例如,在这一行中,您已使用
short
和signed
限定符限定了int
类型the keywords
short
,long
,unsigned
,signed
, etc are called qualifiers. The order of qualifiers is irrelevant, for exampleIn this line you have qualified the
int
type withshort
andsigned
qualifiers您可以使用限定符来指示要在 int 中存储的数字大小。认为确切的大小因 C 的实现而异,但通常如下所示。
短整数a; // 16 位,范围 -32,768 到 32,767
unsigned Short int b; // 16 位,范围 0 到 65,535
unsigned int c; // 32 位,范围 0 到 4,294,967,295
int d; // 32 位,范围 -2,147,483,648 到 2,147,483,647
long int d; // 32 位,范围 -2,147,483,648 到 2,147,483,647(最低要求,64 位系统上可以更高)
You can use Qualifiers to indicate what size of number you want to store inside your int. Think the exact size varies by implementation of C, but typically it's as follows.
short int a; // 16 bits, range -32,768 to 32,767
unsigned short int b; // 16 bits, range 0 to 65,535
unsigned int c; // 32 bits, range 0 to 4,294,967,295
int d; // 32 bits, range -2,147,483,648 to 2,147,483,647
long int d; // 32 bits, range -2,147,483,648 to 2,147,483,647 (minimum requirement, can be higher on 64bit systems)
某些关键字会更改“int”类型的行为。这些被称为限定符。示例包括“短”、“长”、“无符号”、“const”、“易失性”。因此,如果我们用“short”限定“int”,我们就知道该变量至少包含 16 位:
Some keywords change the behaviour of the "int" type. These are known as qualifier. Examples include "short", "long", "unsigned", "const", "volatile". Therefore if we qualify the "int" with "short" we know that the variable contains at least 16 bits:
仅供 ISO 标准澄清 C11
typedef
、extern
、static
、_Thread_local
、auto< /code>,
注册
。void
、char
、short
、int
、long、<代码>浮点、<代码>双精度、<代码>有符号、<代码>无符号、<代码>_Bool、<代码>_Complex
、原子类型说明符_Atomic(
类型名称)
、结构或联合说明符 (struct
和union
)、枚举说明符(enum
)、typedef 名称(typedef
+ 某些内容)。const
、restrict
、易失性
、_Atomic
。_Atomic
类型限定符与_Atomic
类型说明符不同。Just for clarification by ISO standard C11
typedef
,extern
,static
,_Thread_local
,auto
,register
.void
,char
,short
,int
,long
,float
,double
,signed
,unsigned
,_Bool
,_Complex
, atomic-type-specifier_Atomic (
type name)
, struct-or-union-specifier (struct
andunion
), enum-specifier (enum
), typedef-name (typedef
+ something).const
,restrict
,volatile
,_Atomic
.The
_Atomic
type qualifier is not the same thing as the_Atomic
type specifier.从逻辑上讲,整数是从负无穷大到正无穷大的任何整数。
在 C/C++ 中,如果能够声明 int 并使用它来存储任何整数,那就太好了,但不幸的是,可以在 int 数据类型中存储的值的范围必须受到限制。
C/C++ 允许您声明short、int 或long 变量类型,它们分别可以存储2^16、2^32 和2^64 个不同的整数。
说 int 类型是合格的,就等于说它被限制为保存较小的整数子集。
Logically, an integer is any whole number, from negative infinity to positive infinity.
It would be nice in C/C++ to be able to declare an int and use it to store any integer, but unfortunately there have to be limits on the range of values you can store in an int data type.
C/C++ lets you declare short, int or long variable types which can store 2^16, 2^32 and 2^64 distinct whole numbers respectively.
To say that the int type is qualified is the same as saying it's been limited to hold a smaller subset of whole numbers.