Basic Data Types in C++ | DATA Types | Computer Bot

There are various data types. Some of them are discussed here.


Basic Data Types in C++ | DATA Types | Computer Bot

Tokens

Tokens are the smallest or the atomic elements of a language. A program can be written using tokens. C++ has the following tokens:

  • Identifers
  • Keywords
  • Literals
  • Operators
  • Punctuators

Identifiers 

Identifiers are nothing but names. In C++, each of the files, programs, classes, functions, objects, constants and variables have unique identifiers or names. An identifier in C++ is defined as an unlimited sequence of characters, the first of which must be an alphabet followed by digits or underscores or alphabets. Also, lowercase and uppercase alphabets are treated separately and cannot be used interchangeably. Thus, VAR and var represent different names. But you can use both uppercase and lowercase alphabets in the same identifier.

Note carefully that the reserved words cannot be used as identifiers. It is a good practice to coin identifiers which can be associated easily. Therefore, instead of giving names, such as A, B, C, to variables, it is better to have identifiers, such as average, maximum, minimum, etc.

Keywords

A language is designed with a set of instructions, used to communicate with the computer to carry out specific operations. These instructions, which are used in programming, are called keywords. They are also known as reserved words of the language. The program, we wrote in the previous chapter, used class and int, which are reserved words or keywords. They have a specific meaning to a C++ compiler. They should be used for giving specific instructions to the computer. These words cannot be used for any other purpose, like, name of a variable. C++ has seventy-four keywords. We will use most of them in the book. Note that the keywords use only lowercase alphabets.


Read Also :


    Punctuators


    The following characters are used as punctuators in C++.

    • Brackets [ ] - Opening and closing brackets indicate single and multidimensional array subscript.

    • Parentheses ( ) - Opening and closing brackets indicate functions calls, function parameters for grouping expressions etc.

    • Braces { } - Opening and closing braces indicate the start and end of a compound statement.

    Comma , - It is used as a separator in a function argument list.

    • Semicolon ; - It is used as a statement terminator.

    Colon : - It indicates a labelled statement or conditional operator symbol.

    Asterisk * - It is used in pointer declaration or as multiplication operator.

    • Equal sign = - It is used as an assignment operator.

    Pound sign # - It is used as pre-processor directive.

    Literals and operators are discussed ahead in detail.

    C++ Primary Data Types


    Every programming language has its own set of rules about data representation. C++, being an object oriented programming language, supports the following three categories of data types:

    • Primary data type, also called primitive data types or built-in data types.
    • User-defined type, such as structure, class, union and enumeration.
    • Derived data types, such as array, pointer, etc.

    In this section, we will discuss about primary data types and strings which can be considered to be derived data type, but also available as built in type in standard C++. The primary data types are the fundamental ones. C++ supports the following primary data types.

    • Characters - To represent symbols, such as alphabets.
    • Integers - To represent whole numbers.
    • Real numbers - To represent numbers with fractional part.
    • Boolean - To represent logical true or false.
    • Void - To represent absence of information.

    #buttons=(Accept !) #days=(20)

    Our website uses cookies to enhance your experience. Learn More
    Accept !