Let's learn about Tokens in C++

A token is the smallest unit in a cpp program

Types:

  • Identifiers
  • Keywords
  • Operators
  • constants
  • Punctuations

  • 1.Identifiers

    Generally Identifiers are usre created names , they are just named memory blocks wich cans store a specific value or a certained value. for example , i am writing a cpp code for a simple code to get a numerical value as input and then i show that to the user by mutipliying it by 2 ,in this program you will be not introduced to the the structre of cpp, i will get know what is what after a while ,so first i will be teaching you the basic understanding of the tokens in cpp.


    code:
    #include (iostream).
    using namespace std;
    int main()
    {
    int a;
    cout<<"Enter a number:";
    cin>>a;
    cout<<"2 times of "< }

    (note that the iostream should br enclosed within setof (<>) tags , i cant do this because iam typing this website as a brginner in html programming soon i will replace that.)


    Output:
    Enter a number:55
    2 times of 55 is 110

    Explanation: Here in this program we are declaring a variable named "a" to get the input from the user, this is a named memory block this is an identifier.


    Examples:
    Valid Invalid
    sum 11201a
    _int sub total
    val_2 @num

    2.Identifiers

    Keywords are the reserved words which convey specific meaning to the C++ compiler. They are the essential elements to construct C++ programs. Most of the keywords are common to C, C++ and Java.C++ is a case sensitive programming language so, all the keywords must be in lowercase.The below table will give you some example

    Keywords

    Keywords are words wich are predefined by the laguage compiler,'keywords' should not be used as identifier but it can be used as a part of it.

    3.Operators

    The symbols which are used to do some mathematical or logical operations are called as “Operators”. The data items or values that the oper ators act upon are called as “Operands”.In C++, The operators are classified on the basis of the number of operands.

    (i) Unary Operators - Require only one operand
    (ii) Binary Operators - Require two operands
    (iii) Ternary Operators - Require three operands

    For now we are going to just learn about "Binary operators"

    C++ Binary Operators are classified as:

    (1) Arithmetic Operators
    (2) Relational Operators
    (3) Logical Operators
    (4) Assignment Operators
    (5) Conditional Operator