Programming

What are Datatypes in C++ ?

When you create a variable then a first question comes to the mind is that what type of values am I going to store and use it. Let say you want to store your name in a variable. Then you will use respective predefined datatypes like char. Similarily, if you want to store or compute number, you may use int, double, or float, etc. So let’s us see what datatypes are defined in Programming World.

A datatype is a used to restrict the variable with the type of data to be stored. Hence, one can define datatype as a way to tell the variables to store a particular type of data. A compiler always stores the variable according to its datatype, because it assigns a particular amount of memory. Each datatype requires a different amount of memory. For a particular Operating System archiecture, int store 4 bytes of data and char stores 1 byte of data.

Loading...

Data-types are mainly classified into 3 types:

  1. Primitive Data Types: These data types are either built-in or predefined and are used directly while programming by the programmer. For example, int, char, float, bool, etc. These data types are available in ranges like:
    1. Integer
    2. Boolean
    3. Double Floating point
    4. Character
    5. Null
    6. Character
  2. Derived Data Types: These are made from the primitive or built-in datatype, they mainly ranges from function, array, pointer and References. For example,

    int a = sum(a,b);  // here sum is a derived data type.

3. User-Defined Data Types: These data-type are defined by the user. These mainly consist of class, structure ( struct ), Union, TypeDef and Enumeration (Enum). These data-types are used and defined according to the user requirements.

What is Modifiers in Data Type ?

As the name suggest, a modifier is used to modify the content. Similarily, Modifiers in Data Types are used to change the length of the data that a particular data type is made to hold. These are classified into 4 major types:

Loading...
  • Signed
  • Unsigned
  • Short
  • Long

Show More

Leave a Reply

Back to top button