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
- Basic data types or Built in data types
- User defined data types
- 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
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 ..
- Array
- Function
- 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