数据令牌 上下文切换

    科技2022-07-13  128

    数据令牌 上下文切换

    代币:- (Tokens :-)

    These are the small individual units of the program. It includes :-

    这些是程序的小单元。 这包括 :-

    ~> Keywords/Reserved words :- These words are reserved in C++ which holds a special meaning and pre-defined working. Since their work is pre-defined, they only perform the specified function and nothing else. They appear as “white” colored in C++ editor.

    〜> 关键字/保留词:-这些词在C ++中保留,具有特殊含义和预定义的工作方式。 由于其工作是预定义的,因此它们仅执行指定的功能,而没有执行其他操作。 它们在C ++编辑器中显示为“白色”。

    # Example :- “void” is return type, “for” is used as loop, “while” is used as loop, “cin” is used for input, etc.

    #示例:- “ void ”是返回类型,“ for ”用作循环,“ while ”用作循环,“ cin ”用于输入,等等。

    ~> Identifiers :- These are like variables that have some name and stores some value of specified data type.

    〜> 标识符:-这些就像具有某些名称并存储某些指定数据类型值的变量一样。

    ~> Literals :- They are also called constants (variable whose value doesn’t change)

    〜> 文字: -它们也称为常量(其值不变的变量)

    资料类型 (Data Types)

    Data types define the type of data being used by the program to generate output. It’s of different types for different data. Every data must have a specific data type by which it is identified in the program. A particular data cannot have data type of two different types, a data can have only a single data type that defines the data.

    数据类型定义程序用来生成输出的数据类型。 对于不同的数据,它具有不同的类型。 每个数据必须具有在程序中用来标识的特定数据类型。 特定数据不能具有两种不同类型的数据类型,数据只能具有定义该数据的单个数据类型。

    Data types are a part of “<iostream.h>” header file. Some different Data types are as follows :-

    数据类型是“ <iostream.h>”头文件的一部分。 一些不同的数据类型如下:

    Syntax to specify Data Type :- Data_Type Variable_Name;

    指定数据类型的语法 :-Data_Type Variable_Name;

    (Here, Variable_Name is an unspecified data)

    (此处,Variable_Name是未指定的数据)

    #例子:- (# Example :-)

    int a; (Here, “a” is specified as “Integer” type)

    诠释 (此处,“ a”被指定为“整数”类型)

    char b; (Here, “b” is specified as “Character” type)

    字符b; (此处,“ b”被指定为“字符”类型)

    float c; (Here, “c” is specified as “Fractional” type)

    浮动c; (此处,“ c”被指定为“分数”类型)

    double d; (Here, “d” is specified as “Fraction with large point value” type)

    双d; (在此,“ d”被指定为“大分数的分数”类型)

    If there are two or more variables of the same data types required by the program, then you can specify their data type together.

    如果程序需要两个或多个相同数据类型的变量,则可以一起指定它们的数据类型。

    #例子:- (# Example :-)

    int a, b; (Here, both “a” and “b” are specified as “Integer” type)

    整数a,b; (此处,“ a”和“ b”都指定为“整数”类型)

    char c, d, e; (Here, “c”, “d” and “e” all are specified as character types)

    字符c,d,e; (此处,“ c”,“ d”和“ e”都指定为字符类型)

    变数 (Variables)

    A variable is the named memory location whose value remains changing in the entire program, as per user’s needs. Variable is like “x” of algebra used in maths whose value is unknown but can be assigned different values and the assigned values can change according to the person’s needs. The name “variable” signifies varying or changing value.

    变量是命名的内存位置,根据用户的需求,其值在整个程序中保持不变。 变量就像数学中使用的代数的“ x”一样,其值未知,但可以分配不同的值,并且分配的值可以根据人的需要而变化。 名称“变量”表示变化或变化的值。

    A variable needs to be declared with its specific data type so that the data assigned to it should be of specific type.

    需要使用特定的数据类型声明变量,以便分配给它的数据应具有特定的类型。

    Syntax of Variable :-

    变量的语法 :-

    Data_Type Variable_Name; (In this declaration, there is value assigned to variable)

    Data_Type变量名称; (在此声明中,已为变量分配了值)

    Data_Type Variable_Name = Value; (In this declaration, a value is assigned to variable using “=”)

    Data_Type Variable_Name =值; (在此声明中,使用“ =”将值分配给变量)

    [A variable must contain the value according to its data type.]

    [变量必须根据其数据类型包含值。]

    命名变量规则: (Rules for Naming Variables :-)

    → First character must be an alphabet. It can’t be any integer (1,2,3,4,……) or special character (@,#,$,%,….).

    →第一个字符必须是字母。 它不能是任何整数(1,2,3,4,……)或特殊字符(@,#,$,%,....)。

    → Name of variable should be according to the program’s concept. The name should resemble the purpose of the variable.

    →变量名称应根据程序的概念。 名称应类似于变量的用途。

    → No reserve word/identifier can be used as variable or function name.

    →不能将保留字/标识符用作变量或函数名称。

    → Spaces or Special symbols cannot appear in between variable name.

    →变量名称之间不能出现空格或特殊符号。

    → Only Underscore “ _ ” can be used in place of space.

    →只能使用下划线“ _”代替空格。

    → Variable name cannot be very long, it should be as small as possible.

    →变量名不能太长,应尽可能小。

    #示例:- (# Example:-)

    int 1a, @b ; (//Invalid, numbers and special characters can’t be the first character)

    int 1a,@b ; (//无效,数字和特殊字符不能为第一个字符)

    int cin, cout ; (//Invalid, “cin” and “cout” are reserved words)

    int cin,cout; (//无效,“ cin”和“ cout”是保留字)

    int number count ; (//Invalid, spaces can’t be put in between variable name)

    整数计数; (//无效,变量名之间不能插入空格)

    int number@count ; (//Invalid, special character can’t be put in between variable name)

    int number @ count; (//无效的,不能在变量名之间插入特殊字符)

    int number_count_of_cars ; (//Valid, but too long, must be short)

    int number_count_of_cars; (//有效,但太长,必须短)

    int num_count; (//Valid, fulfills all necessary conditions)

    int num_count; (//有效,满足所有必要条件)

    The value of a variable can be changed anytime, kinda like overwritten. If a variable has a value assigned to it, then the user can overwrite that value with another value and the first value will get deleted.

    变量的值可以随时更改,有点像被覆盖。 如果为变量分配了一个值,则用户可以用另一个值覆盖该值,第一个值将被删除。

    常数 (Constants)

    Constants, also known as Literals, are the valid values of a variable. They are of different types :-

    常量,也称为文字,是变量的有效值。 它们是不同类型的:

    ~> Integer Constant :- It contains all the numbers in their natural form (without any decimal point).

    〜> 整数常量:-包含所有自然形式的数字(无小数点)。

    # Example :- 1325, 845, 123, 45, 7942, etc.

    # 示例 :-1325、845、123、45、7942等。

    Integer constant contains the numbers from 0–9.

    整数常量包含从0到9的数字。

    ~> Floating Constant :- These are the constants which are in numeral form where there must be at least one digit before the decimal point and one after the decimal point. They are also called “Real Constant”.

    〜> 浮点常数:-这些是数字形式的常数,其中小数点前必须至少有一位数字,小数点后必须至少一位数字。 它们也称为“实常数”。

    # Example :- 2.6, 23.7, 2.45, 345.6, 1.546, etc. (//All valid values)

    # 示例 :-2.6、23.7、2.45、345.6、1.546等 (//所有有效值)

    3. , .5 , 245. , .356, etc. (//All invalid values)

    3。,。5、245,.356等 (//所有无效值)

    Real or Floating constants can be expressed in Exponential form but there should be at least two digits present before “E” and a digit for the exponent.

    实常数或浮点常数可以用指数形式表示,但“ E”之前应至少有两位数字和指数的一位。

    # Example :- 345E14, 5422E256, etc. (//All valid values, “E” expresses exponent)

    # 示例 :-345E14、5422E256等 (//所有有效值,“ E”表示指数)

    235E , 13E , 1E24, 3E4, etc. (//All invalid values)

    235E,13E,1E24,3E4等 (//所有无效值)

    ~> Character Constant :- Character constant contains single character or special character enclosed in single quotes ( ‘ ’ ).

    〜> 字符常量:-字符常量包含 用单引号('')引起的单字符或特殊字符。

    # Example :- ‘A’, ‘@’, ‘a’, ‘+’, etc.

    # 示例 :-'A','@','a','+'等

    Character constant occupies 1 byte per character for storage.

    字符常量每个字符占用1个字节用于存储。

    ~> String Constant :- It contains more than one character (sequence/collection of characters) enclosed in double-quotes. For storage, they occupy one extra byte than the mentioned length/size because a string termination symbol called NULL character “\0” is automatically added in the memory. Here, size/length means the number of characters that can be put to make a string.

    〜> 字符串常量:-它包含多个用双引号引起来的字符(字符的序列/集合)。 为了存储,它们会比上述长度/大小多占用一个字节,因为会在内存中自动添加一个称为NULL字符“ \ 0”的字符串终止符号。 此处,大小/长度是指可以放入字符串中的字符数。

    Syntax :- char Variable_name[size]; (//Variable_name can be anything and size has to be assigned by the user)

    语法 : -char Variable_name [size]; (// Variable_name可以是任何东西,并且大小必须由用户分配)

    # Example :- char Word[5]; (//Here “Word” is Variable and “[5]” is the size of variable “Word”)

    #示例: -char Word [5]; (//这里“ Word”是变量,“ [5]”是变量“ Word”的大小)

    (Here, the front 4 boxes are for initialization/give value or data and the last box is automatically occupied by the “NULL” character. Users must always input one byte more than required in order to get a favorable result.)

    (在这里,前4个框用于初始化/给定值或数据,最后一个框自动由“ NULL”字符占用。用户必须始终输入比要求多的一个字节才能获得满意的结果。)

    #例子:- (# Example :-)

    char Word[5]=”Hello”; (//The program will only accept “Hell” and omit “o” or might sometimes give an error)

    char Word [5] =“ Hello”; (//程序将仅接受“ Hell”并省略“ o”,否则有时可能会出现错误)

    char Word[5]=”Blue”; (//The program will accept the complete word and won’t show any error)

    char Word [5] =“ Blue”; (//程序将接受完整的单词,并且不会显示任何错误)

    注释 (Comments)

    They are the non-executable portion of any program which is ignored by the compiler during program execution. They don’t have any visual representation (don’t appear in output). They are used to give additional information about the program or the specific part of the program. They are of 2 types :-

    它们是任何程序的不可执行部分,在程序执行期间编译器会忽略它们。 它们没有任何视觉表示(不会出现在输出中)。 它们用于提供有关程序或程序特定部分的其他信息。 它们有2种类型:

    ~> Single-Line Comment :- When a comment is given only in one line.

    〜> 单行注释:-仅在一行中给出注释时。

    Syntax :- //Comment (//Comment is written after “//” symbol only in the start)

    语法 :- //注释 (//注释仅在开始处的“ //”符号后写)

    # Example :- //Program to count words.

    #示例:- //程序计算单词。

    //Formula to calculate Area

    //计算面积的公式

    ~> Multi-Line Comment :- When the comments are given in two or more lines.

    〜> 多行注释:-在两行或更多行中给出注释时。

    S

    小号

    /* Comment

    / *评论

    Comment

    评论

    Comment

    评论

    Comment */

    评论* /

    (/* Comments start after “ /* ” symbol and keeps on going for multiple lines and ends at “ */ “ symbol */)

    (/ *注释以“ / *”符号开头,并持续多行,并以“ * /”符号* /结束)

    # Example :- /* Program to find reverse and calculate number of words. */

    # 示例:- / *程序查找反向并计算单词数。 * /

    Here is a little code for you to understand above mentioned concepts and get to know a few more commands :-

    这里有一些代码供您理解上述概念并了解更多命令:-

    The mentioned displays declaration of Variables along with their specified Data types. The code also shows a new Command :-

    提到的显示变量的声明以及它们指定的数据类型。 该代码还显示了一个新命令:

    “cin” Command :- This command is used to order the computer to demand the input of values for uninitialized Variables. It’s the opposite of “cout” command which displays the input data. This command doesn’t require “ “ symbol but it does require extraction operator “>>”. It’s a function of “<iostream.h>” header file.

    “ cin”命令 :-该命令用于命令计算机要求输入未初始化变量的值。 这与显示输入数据的“ cout”命令相反。 该命令不需要“”符号,但需要提取运算符“ >> ”。 它是“ <iostream.h>”头文件的功能。

    Syntax for cin :- cin>>Variable_name; (// “>>” and “;” are necessary for the code to run)

    cin的语法:- cin >> Variable_name; (//“ >>”和“;”是运行代码所必需的)

    When executed, the user has to provide value to the variable, which is used by the program for further output.

    执行时,用户必须为变量提供值,程序将其用于进一步输出。

    Well, today we were able to cover some important topics which includes :-

    好吧,今天我们能够涵盖一些重要的主题,包括:

    ~> Tokens :- Keywords, Identifiers and Literals.

    〜>令牌:-关键字,标识符和文字。

    ~> Data types :- int, char, float, and double.

    〜>数据类型:-int,char,float和double。

    ~> Variable :- A named memory location with varying value.

    〜>变量:-具有不同值的命名内存位置。

    ~> Constants :- Integer constant, Floating constant, Character constant, and String Constant.

    〜>常量:-整数常量,浮点常量,字符常量和字符串常量。

    ~> Comments :- Single-Line and Multi-Line comments.

    〜>注释:-单行和多行注释。

    ~> “cin” command :- Command used to input data.

    〜>“ cin”命令:-用于输入数据的命令。

    This sums up all the explanation for today.

    总结了今天的所有解释。

    If you have any questions or queries regarding any topic, then please do let me know in the comments. I will try my best to solve that problem of yours.

    如果您对任何主题有任何疑问或疑问,请在评论中让我知道。 我将尽力解决您的问题。

    Be tuned for the next part which will cover a new program with some new topics.

    敬请关注下一部分,该部分将介绍具有一些新主题的新程序。

    翻译自: https://medium.com/swlh/tokens-data-types-variables-constants-and-comments-b33f92c1f597

    数据令牌 上下文切换

    Processed: 0.010, SQL: 8