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

发布于 2024-10-19 01:03:27 字数 361 浏览 3 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

卖梦商人 2024-10-26 01:03:27

限定符是给变量或函数的额外名称,显示该变量或函数的额外质量或额外含义。就像 Dr Arun Kumar 中的 Dr

变量的限定符是(类型限定符):signedunsignedlongshort , long long, const, 易失性, 静态, 自动, externregister

函数的限定符有:staticexterninline

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

枯寂 2024-10-26 01:03:27

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

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

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

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

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

In this line you have qualified the int type with short and signed qualifiers

分分钟 2024-10-26 01:03:27

您可以使用限定符来指示要在 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)

懒的傷心 2024-10-26 01:03:27

某些关键字会更改“int”类型的行为。这些被称为限定符。示例包括“短”、“长”、“无符号”、“const”、“易失性”。因此,如果我们用“short”限定“int”,我们就知道该变量至少包含 16 位:

short int var;

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:

short int var;
沐歌 2024-10-26 01:03:27

仅供 ISO 标准澄清 C11

  • 存储-class 说明符 (6.7.1):typedefexternstatic_Thread_localauto< /code>,注册
  • 类型说明符 (6.7.2):voidcharshortintlong、<代码>浮点、<代码>双精度、<代码>有符号、<代码>无符号、<代码>_Bool、<代码>_Complex、原子类型说明符 _Atomic(类型名称、结构或联合说明符 (structunion)、枚举说明符(enum)、typedef 名称(typedef + 某些内容)。
  • 类型限定符 (6.7.3):constrestrict易失性_Atomic

_Atomic 类型限定符与 _Atomic 类型说明符不同。

Just for clarification by ISO standard 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 (struct and union), enum-specifier (enum), typedef-name (typedef + something).
  • Type Qualifiers (6.7.3): const, restrict, volatile, _Atomic.

The _Atomic type qualifier is not the same thing as the _Atomic type specifier.

倾听心声的旋律 2024-10-26 01:03:27

从逻辑上讲,整数是从负无穷大到正无穷大的任何整数。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文