C ++中的数据类型和修饰符

Let's start with Datatypes. They are used to define type of variables and contents used. Data types define the way you use storage in the programs you write. Data types can be of two types:

让我们从数据类型开始。 它们用于定义变量的类型和使用的内容。 数据类型定义您在编写的程序中使用存储的方式。 数据类型可以有两种类型:

  1. Built-in Datatypes

    内置数据类型

  2. User-defined or Abstract Datatypes

    用户定义或抽象数据类型

内置数据类型 (Built-in Data Types)

These are the datatypes which are predefined and are wired directly into the compiler. For eg: int, char etc.

这些是预定义的数据类型,可直接连接到编译器中。 例如: intchar等。

用户定义或抽象数据类型 (User defined or Abstract data types)

These are the type, that user creates as a class or a structure. In C++ these are classes where as in C language user-defined datatypes were implemented as structures.

这些是用户作为类或结构创建的类型。 在C ++中,这些类与在C语言中一样,用户定义的数据类型被实现为结构。

C ++中的基本内置数据类型 (Basic Built in Datatypes in C++)

charfor character storage (1 byte)
intfor integral number (2 bytes)
floatsingle precision floating point (4 bytes)
doubledouble precision floating point numbers (8 bytes)
char 用于字符存储(1个字节)
int 用于整数(2个字节)
float 单精度浮点数(4个字节)
double 双精度浮点数(8字节)

Example:

范例

char a = 'A';          // character type
int a = 1;             // integer type
float a = 3.14159;     // floating point type 
double a = 6e-4;       // double type (e is for exponential)

C ++中的其他内置数据类型 (Other Built in Datatypes in C++)

boolBoolean (True or False)
voidWithout any Value
wchar_tWide Character
bool 布尔值(真或假)
void 没有任何价值
wchar_t 宽字符

在C ++中将Enum作为数据类型 (Enum as Datatype in C++)

Enumerated type declares a new type-name along with a sequence of values containing identifiers which has values starting from 0 and incrementing by 1 every time.

枚举类型声明一个新的类型名称,以及一系列包含标识符的值序列,这些标识符的值从0开始,每次递增1。

For Example:

例如:

enum day(mon, tues, wed, thurs, fri) d;

Here an enumeration of days is defined which is represented by the variable d. mon will hold value 0, tue will have 1 and so on. We can also explicitly assign values, like, enum day(mon, tue=7, wed);. Here, mon will be 0, tue will be assigned 7, so wed will get value 8.

此处定义了天的枚举,它由变量d表示。 星期一将保持值0星期二将具有1 ,依此类推。 我们还可以显式分配值,例如enum day(mon, tue=7, wed); 。 在这里, mon将为0星期二将被分配为7 ,因此wed将获得值8

In C++, special words(called modifiers) can be used to modify the meaning of the predefined built-in data types and expand them to a much larger set. There are four datatype modifiers in C++, they are:

在C ++中,可以使用特殊词(称为修饰符 )来修改预定义的内置数据类型的含义,并将其扩展为更大的集合。 C ++中有四个数据类型修饰符,它们是:

  1. long

    long

  2. short

    short

  3. signed

    signed

  4. unsigned

    unsigned

The above mentioned modifiers can be used along with built in datatypes to make them more precise and even expand their range.

上面提到的修饰符可以与内置数据类型一起使用,以使它们更精确甚至扩展其范围。

Below mentioned are some important points you must know about the modifiers,

下面提到的是有关修饰符的一些重要知识,

  • long and short modify the maximum and minimum values that a data type will hold.

    longshort修改数据类型将保留的最大值和最小值。

  • A plain int must have a minimum size of short.

    一个普通的int必须具有short的最小大小。

  • Size hierarchy : short int < int < long int

    大小层次结构: short int < int < long int

  • Size hierarchy for floating point numbers is : float < double < long double

    浮点数的大小层次结构为: float < double < long double

  • long float is not a legal type and there are no short floating point numbers.

    长浮点数不是合法类型,并且没有短浮点数

  • Signed types includes both positive and negative numbers and is the default type.

    带符号的类型包括正数和负数,并且是默认类型。

  • Unsigned, numbers are always without any sign, that is always positive.

    无符号 ,数字始终没有任何符号,始终为正。

翻译自: https://www.studytonight.com/cpp/datatypes-and-modifiers-in-cpp.php

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值