C语言 C语言中的限定符是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5103726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 07:52:10  来源:igfitidea点击:

What are Qualifiers in the C language?

cqualifiers

提问by ipkiss

I am reading some text at this url:

我正在这个网址阅读一些文字:

https://cs.senecac.on.ca/~btp100/pages/content/varia_p.html

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: ....

“我们可以限定 int 类型以确保它包含最少数量的位”.... 一个 short 至少包含 16 位:....

I don't understand this, what does "qualify the int type" mean and why "A short contains at least 16 bits".

我不明白这一点,“限定 int 类型”是什么意思以及为什么“短包含至少 16 位”。

Can anybody elaborate on this please? Thanks all.

有人可以详细说明一下吗?谢谢大家。

采纳答案by Tom Jefferys

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.

您可以使用限定符来指示要在 int 中存储的数字大小。认为确切的大小因 C 的实现而异,但通常如下所示。

short int a; // 16 bits, range -32,768 to 32,767

short int a; // 16 bits, range -32,768 to 32,767

unsigned short int b; // 16 bits, range 0 to 65,535

unsigned short int b; // 16 bits, range 0 to 65,535

unsigned int c; // 32 bits, range 0 to 4,294,967,295

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

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)

long int d; // 32 bits, range -2,147,483,648 to 2,147,483,647 (minimum requirement, can be higher on 64bit systems)

回答by BIJU

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

变量的限定符是(TYPE 限定符):signed, unsigned, long, short, long long, const, volatile, static, auto, extern,register

Qualifiers for functions are: static, extern, inline

函数的限定符是:static, extern,inline

回答by Armen Tsirunyan

the keywords short, long, unsigned, signed, etc are called qualifiers. The order of qualifiers is irrelevant, for example

关键字shortlongunsignedsigned等称为限定符。限定符的顺序无关紧要,例如

short int signed x; // means signed short int x, at least 16 bits :)

In this line you have qualified the inttype with shortand signedqualifiers

在这一行中,您int使用shortsigned限定符限定了类型

回答by qbert220

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:

一些关键字改变了“int”类型的行为。这些被称为限定符。示例包括“short”、“long”、“unsigned”、“const”、“volatile”。因此,如果我们用“short”限定“int”,我们就知道该变量至少包含 16 位:

short int var;

回答by user632166

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++ 中能够声明一个 int 并使用它来存储任何整数会很好,但不幸的是,您可以存储在 int 数据类型中的值的范围必须有限制。

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.

C/C++ 允许您声明可分别存储 2^16、2^32 和 2^64 不同整数的 short、int 或 long 变量类型。

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.

说 int 类型是合格的,就等于说它被限制为容纳较小的整数子集。

回答by Undefined Behavior

Just for clarification by ISO standard C11

仅供 ISO 标准C11澄清

  • Storage-class Specifiers (6.7.1): typedef, extern, static, _Thread_local, auto, register.
  • Type Specifiers (6.7.2): void, char, short, int, long, float, double, signed, unsigned, _Bool, _Complex, atomic-type-specifier _Atomic (type name), struct-or-union-specifier (structand union), enum-specifier (enum), typedef-name (typedef+ something).
  • Type Qualifiers (6.7.3): const, restrict, volatile, _Atomic.
  • 存储类说明符 (6.7.1):typedef, extern, static, _Thread_local, auto, register.
  • Type Specifiers (6.7.2): void, char, short, int, long, float, double, signed, unsigned, _Bool, _Complex, atomic-type-specifier _Atomic (type name), struct-or-union-specifier ( structand union), enum-specifier ( enum), typedef-name ( typedef+ something )。
  • 类型限定符 (6.7.3): const, restrict, volatile, _Atomic.

The _Atomictype qualifier is not the same thing as the _Atomictype specifier.

_Atomic类型修饰符是不一样的东西作为_Atomic类型说明符。