c++ 意外的令牌标识符_C ++令牌–关键字,常量,标识符,字符串,运算符和特殊符号

c++ 意外的令牌标识符

Here you will learn about C++ tokens, keywords, constants, identifiers, strings, operators and special symbols.

在这里,您将了解C ++令牌,关键字,常量,标识符,字符串,运算符和特殊符号。

What are Tokens?

什么是代币?

In simple words, we can say that tokens are the smallest component pertaining to any program that make sense to the compiler, i.e. compiler can very easily understand that. We can classify the tokens into six different sub-categories as follows:

用简单的话来说, 令牌是与任何对编译器有意义的程序有关的最小组件,即编译器可以很容易地理解这一点。 我们可以将令牌分为以下六个不同的子类别:

  • Keywords

    关键词
  • Constants

    常数
  • Strings

    弦乐
  • Identifiers

    身份标识
  • Operators

    经营者
  • Special Symbols

    特殊符号

Now we are going to illustrate these one by one and will see what exactly they mean.

现在,我们将逐一说明这些内容,并了解它们的确切含义。

关键词 (Keyword)

The keywords are the reserved terms in any programming language. Every keyword in the language is expected to provide an intended functionality to the program. We cannot use the keywords  as variable names because this practice tries to assign a new meaning to the keyword which is not appreciated nor allowed in any programming language. However, the C/C++ pre-processor directives (so-called header files) can be used to specify text to be exchanged for keywords before compilation. C language preferably supports for 32 keywords that we have mentioned in the tabular form below:

关键字是任何编程语言中的保留术语。 语言中的每个关键字都有望为程序提供预期的功能。 我们不能将关键字用作变量名,因为这种做法试图为关键字赋予新的含义,而这在任何编程语言中都是无法理解的。 但是,可以使用C / C ++预处理程序指令(所谓的头文件 )来指定要在编译之前交换关键字的文本。 C语言最好支持以下表格中提到的32个关键字:

doforfloatcontinue
voidelseifswitch
structenumregisterchar
typedefstaticreturndefault
constintshortvolatile
whiledoublebreaksigned
unionlongsizeofunsigned
externgotoautocase
对于 浮动 继续
虚空 其他 如果 开关
结构 枚举 寄存器 烧焦
类型定义 静态的 返回 默认
const 整型 易挥发的
打破
联盟 大小 未签名
外部 汽车 案件

Apart from supporting these 32 keywords, C++ has 31 more keywords which are:

除了支持这32个关键字外,C ++还有31个关键字,分别是:

typeidfalsecatchnew
thisdeletetryexplicit
exporttypenameusinginline
asmnamespaceclassthrow
privateprotectedpublictrue
static_casttemplateconst_castoperator
reinterpret_castdynamic_castmutablebool
friendvirtualwchar_t
型别 抓住
这个 删除 尝试 显性的
出口 类型名 使用 排队
汇编 命名空间
私人的 受保护的 上市 真正
static_cast 模板 const_cast 算子
reinterpret_cast dynamic_cast 易变的 布尔
朋友 虚拟 wchar_t

常数 (Constants)

Constants are normally the variables. The only thing that differentiates Constants from Variables is the fact that it is not allowed to modify the value of a constant by the program after the constants have already been defined.

常量通常是变量。 唯一可以将常量与变量区分开的地方是,在定义常量之后,程序不允许修改常量的值。

Constants refer to fixed values.

常数是指固定值。

Constants are also sometimes referred as Literals.

常量有时也称为文字。

They may belong to any of the data types.

它们可能属于任何数据类型。

Constant types

常量类型

  • Integer constants: For example: 0, 5, 957, 12376 etc.

    整数常数:例如:0、5、957、12376等。

  • Floating Point / Real constants: For example: 0.7, 8.65, 4587.05 etc.

    浮点数/实常数:例如:0.7、8.65、4585.05等。

  • Octal and Hexadecimal constants: For example:

    八进制和十六进制常量:例如:

    • Octal: (15)8  = (13)10

      八进制:(15) 8 =(13) 10

    • Hexadecimal: (015)16 = (21)10

      十六进制:(015) 16 =(21) 10

    Octal and Hexadecimal constants: For example:

    八进制和十六进制常量:例如:

  • Character constants: For example: ‘a’, ‘A’, ‘x’, ‘Z’ etc.

    字符常量:例如:“ a”,“ A”,“ x”,“ Z”等。

  • String constants:  For example: “TheCrazyProgrammer”

    字符串常量:例如:“ TheCrazyProgrammer”

弦乐 (Strings)

Strings are regarded as an array of characters, ending with a null character “\0”. The null character is used to point the ending of the specified string.

字符串被视为字符数组,以空字符“ \ 0”结尾。 空字符用于指向指定字符串的结尾。

Strings, in practical use are expected to be enclosed in double quotes (“ ”), whereas the character within single quotes (‘ ’).

实际使用中的字符串应该用双引号(“)括起来,而字符用单引号('')括起来。

C++ Tokens 1

The above declarations can be illustrated as:

上面的声明可以说明为:

  1. When char is declared as “flag[25]”, that means 25 bytes of space in the memory is provided for accommodating the value of the string.

    当char声明为“ flag [25]”时,这意味着将在内存中提供25个字节的空间来容纳字符串的值。
  2. But when we’ve declared char as “flag[]”, the space in the memory will be provided by the CPU strictly according to the requirement at runtime.

    但是,当我们将char声明为“ flag []”时,内存中的空间将严格由CPU在运行时根据要求提供。

身份标识 (Identifiers)

Identifiers are saviors. We can use them as the general terminology for the naming purpose of variables, arrays, and functions. Identifiers are the user-defined names which may consist of a long sequence of letters and digits with either a letter or the underscore (_) as a first character.

标识符是救星。 我们可以将它们用作变量,数组和函数的命名的通用术语。 标识符是用户定义的名称,可以由一长串字母和数字组成,以字母或下划线(_)作为第一个字符。

Keywords can’t be used as identifiers, as they are reserved for special purpose. To use the identifiers in program statements we need to declare it in the program itself.

关键字不能用作标识符,因为它们是为特殊目的而保留的。 要在程序语句中使用标识符,我们需要在程序本身中声明它。

Rules for naming C++ identifiers

C ++标识符的命名规则

  • Identifiers must begin with a letter or underscore( _ ).

    标识符必须以字母或下划线(_)开头。
  • No special characters are allowed in identifier naming, only letters, digits or underscores can be used.

    标识符命名中不允许使用特殊字符,只能使用字母,数字或下划线。
  • A keyword can’t be an identifier.

    关键字不能是标识符。
  • White space is not allowed within identifier

    标识符内不允许有空格
  • It should only be up to 31 characters long, as only first 31 characters are significant.

    它最多只能包含31个字符,因为只有前31个字符有效。

C identifiers examples

C标识符示例

C++ Tokens 2

经营者 (Operators)

The operators are the symbols that are commonly used to trigger some action when applied to variables or other objects. The operator needs some data items to act upon, those data items are referred to as Operands. For example in (a + b), ‘+’ sign is the operator whereas ‘a’ & ‘b’ are the operands.

运算符是应用于变量或其他对象时通常用于触发某些操作的符号。 操作员需要一些数据项才能执行操作,这些数据项称为操作数。 例如,在(a + b)中,“ +”号是运算符,而“ a”和“ b”是操作数。

Types of Operators

运营商类型

  • Unary Operators: The operators that work upon a single operand only are called Unary Operators. Example:- Increment & decrement operators.

    一元运算符:仅对单个操作数进行运算的运算符称为一元运算符。 示例:-增量和减量运算符。

  • Binary Operators: As clear from its name itself, Binary Operators are those which require two different operands to work upon. They can be classified into:

    二进制运算符:从其名称本身可以清楚地看出,二进制运算符是需要两个不同操作数进行运算的运算符。 它们可以分为:

    1. Arithmetic Operators

      算术运算符
    2. Relational Operators

      关系运算符
    3. Logical Operators

      逻辑运算符
    4. Assignment Operators

      赋值运算符
    5. Conditional Operators

      条件运算符
    6. Bitwise Operators

      按位运算符

    Binary Operators: As clear from its name itself, Binary Operators are those which require two different operands to work upon. They can be classified into:

    二进制运算符:从其名称本身可以清楚地看出,二进制运算符是需要两个不同操作数进行运算的运算符。 它们可以分为:

  • Ternary Operators: The operators that require three different operands to work upon are known as Ternary Operators. Conditional Operator (?:) is an example of ternary operator.

    三元运算符:需要三个不同操作数进行运算的运算符称为三元运算符。 条件运算符(?:)是三元运算符的一个示例。

特殊符号 (Special Symbols)

The symbols that are used in C/C++ with some special meaning and for some specific function are called as Special Symbols.

在C / C ++中使用的具有特殊含义和某些特定功能的符号称为特殊符号。

The special symbols being used with context to programming language are illustrated below as:

与编程语言的上下文一起使用的特殊符号如下所示:

  • Brackets []: These opening and closing brackets are used as array element reference. These are used to indicate single & multidimensional subscripts.

    括号[]:这些左括号和右括号用作数组元素参考。 这些用于指示单维和多维下标。

  • Braces {}: Opening and closing curly braces are used to mark start and end of a block of code containing more than one statement.

    大括号{}:大括号和大括号用于标记包含多个语句的代码块的开始和结束。

  • Comma ( , ): To separate more than one statement, Comma is used for example in for loop comma separates initialization, condition & increment.

    逗号(,):要分隔多个语句,例如,在for循环中使用逗号,逗号分隔初始化,条件和增量。

  • Semicolon ( ; ): Used at the end of statements for termination.

    分号(;):在语句末尾用于终止。

  • Parenthesis () : Are used to indicate function parameters & function calls.

    括号():用于指示函数参数和函数调用。

  • Asterick ( * ): This special symbol is used to create a pointer variable.

    Asterick(*):此特殊符号用于创建指针变量。

  • Assignment Operator ( = ): For assigning values, this special symbol is used.

    赋值运算符(=):对于赋值,使用此特殊符号。

  • Preprocessor ( # ): This you must have seen attached with the header files. This is automatically used by the compiler to transform your program before actual compilation.

    预处理程序(#):您必须已经看到该文件与头文件一起附加了。 在实际编译之前,编译器会自动使用它来转换程序。

 Reference: http://www.geeksforgeeks.org/cc-tokens/

参考: http : //www.geeksforgeeks.org/cc-tokens/

Comment below if you have any queries related to above C++ tokens tutorial.

如果您对以上C ++令牌教程有任何疑问,请在下面评论。

翻译自: https://www.thecrazyprogrammer.com/2017/11/c-tokens.html

c++ 意外的令牌标识符

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值