What are Qualifiers in the C language?

柔情痞子 提交于 2019-12-19 08:18:09

问题


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.


回答1:


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)




回答2:


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




回答3:


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




回答4:


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;



回答5:


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.




回答6:


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.



来源:https://stackoverflow.com/questions/5103726/what-are-qualifiers-in-the-c-language

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!