data types in c++

Data Types in C++ -: Data types define the type of data a variable can store for an example an integer variable store integer data and  a character type variable store character data.

In other words we can say that the data type store the variable value. In  the C++ programming has 3 type of data types. These are

  1.  Basic data types or Built in data types
  2. User defined data types
  3. Derived data types

 

 

Basic Data Type in C++ programming language-:  Both the C language and C++ compiler support all the built in data type. This is know the basic data type or fundamental data type. With the exception of void the basic data type may has several modifiers preceding them to serve the needs of various situation.

The Modifiers signed, Unsigned Long and short may be applied to character and integer basic data types. List of basic data type has been given here in this image

data type in c++
data type in c++

 

2. User Defined Data Type in C++ programming language- C++ also permit user define data types  these are the

  • Structure and classes :  We have used user define data such as struct and union in C  while these data types are Legal in C++ programming language.  C++ also permit user define data type this is known as the class which can be used just like any other basic data types to declare a variable. The class variable are known as object.
  • Enumerated Data Type -: An enumerated data type is another user defined data type which provide a way for attaching a name to number thereby increasing comprehensibility of the code  for example
  •  enum shape { circle,square,triangle };
     enum colour { red,yellow,green};
     enum position { off,on};

     

Derived Data Types In C++ programming Language -: In the Derived data type are in  C++ programming language has ..

  1. Array
  2. Function
  3. Pointer

Array-: This is the same in C language. Only exception is the way character array are initialized. When Initialing a character array in C, the compiler will allow us to declare the array as the exact length of the string constant. For example

char string [3]=" ABC"    // It is valid in c

While in C++ 

char string [4]="ABC"   // it is valid in c++

 

Function derived data type in c++-: Function have undergone major change in c++. While some of these changes are simple other require a new way of thinking when organizing our program.

Pointer derived data types -: Pointers are extensively used in C++ for memory management and achieving polymorphism. C++ adds the concept of constants pointer and pointer to constant.

char * constant ptrl ="good";


we can not modified the address the ptrl is initialized

 

Leave a Comment