Wednesday 23 August 2017

Data Types in C++

while doing programming in any programming language, you need some specific words to tell the compiler. Here I will explain these words.

TOKENS:-it is the smallest unit in a program, these are of five types.


  1. Keywords:-These are the words that convey a special meaning to the language compiler like default, case, break etc.
  2. Identifiers:-It is the name given by the user for a unit of the program.Identifiers can contain letters and digits.example are MYFILE,_DS,z2t0z9.
  3. Literals:-These are data items that never change their value during a program run (often referred to as constants).examples integer-constant,character-constant,floating-constant,string-literal.
  4. Punctuators:-It enhance a program's readability and give proper meaning to statements, expressions etc as per syntax. examples are {},[ ].
  5. Operators:-These are tokens that trigger some computation or action when applied to the variable and other objects in an expression.examples are arithmetic operators, logical operators, relational operators, conditional operators.i will explain it further.
DATA TYPES:-Data types are means to identify the type of data and associated operations for handling it.C++ data types are of two types:-

  1. Fundamental data types: These are those that are not composed of other data types.These are six fundamental data types in C++.
  • Int Data type: Int stores integer i.e. 34,-678 etc.They have no fractional parts.
  • Char Data type: Char stores character.character can store character variable.examples are &,b,% and 3.
  • Float Data type: Float stores floating-point numbers.it stores number having integer plus fractional part.example are  8.98888,7.89.
  • Double Data type: Double stores twice as int and float.
  • Void Data type: The void type specifies an empty set of values.It is used as the return type for functions that do not return a value.
  • Bool Data type: Bool stores Boolean algebra.It stores either true or false.

DATA TYPES MODIFIERS:-Expect type void, the basic data types can be modified by using modifiers such as


  • signed
  • unsigned 
  • long 
  • short
     2.Derived Data Type: These are derived from the fundamental data type.


  • Array: Arrays refer to a named list of a finite number n of similar data elements.Examples are ary[1],ary[2].......ary[n].
  • Function: A function is a named part of a program that can invoke from other parts of the program as often needed.
  • Pointer: A pointer is a variable that holds a memory address(type *ptr).
  • Reference: A reference is an alternative name of an object.The general declaring of reference variable is :type &ref-var=var-name;
  • Constant: The keyword const can be added to the declaration of an object to make that object a constant rather than a variable.The general declaration of constant is -const type name=value;




  • User-Defined Derived Data Types:-There are some derived data types that are defined by the user.
  1. Class:- A class represent a group of similar objects.
  2. Structure: A structure is a collection of variables referenced under one name, providing convenient means of keeping related information together.
  3. Union: A union is a memory location that is shared by two or more different variables, generally of different types at different times.
  4. Enumeration:- An alternative method for naming integer constants is often more convenient than const.
more information will be provided on these topics as we go deeper in C++.



0 comments:

Post a Comment