📅  最后修改于: 2020-12-17 05:03:18             🧑  作者: Mango
C++允许char,int和double数据类型在它们前面有修饰符。修饰符用于更改基本类型的含义,以使其更精确地适合各种情况的需求。
数据类型修饰符在这里列出-
可以将带符号,无符号,长和短的修饰符应用于整数基类型。另外,有符号和无符号可以应用于char,而long可以应用于double。
带符号和无符号的修饰符也可以用作长或短修饰符的前缀。例如, unsigned long int 。
C++允许使用简写形式来声明无符号,短或长整数。您可以简单地使用unsigned,short或long来表示int 。它自动暗示int 。例如,以下两个语句都声明无符号整数变量。
unsigned x;
unsigned int y;
要了解C++解释有符号整数修饰符和无符号整数修饰符的方式之间的区别,您应该运行以下简短程序-
#include
using namespace std;
/* This program shows the difference between
* signed and unsigned integers.
*/
int main() {
short int i; // a signed short integer
short unsigned int j; // an unsigned short integer
j = 50000;
i = j;
cout << i << " " << j;
return 0;
}
运行该程序时,输出如下-
-15536 50000
上面的结果是因为将50,000表示为短无符号整数的位模式被短解释为-15,536。
类型限定符提供有关它们之前的变量的其他信息。
Sr.No | Qualifier & Meaning |
---|---|
1 |
const Objects of type const cannot be changed by your program during execution. |
2 |
volatile The modifier volatile tells the compiler that a variable’s value may be changed in ways not explicitly specified by the program. |
3 |
restrict A pointer qualified by restrict is initially the only means by which the object it points to can be accessed. Only C99 adds a new type qualifier called restrict. |