DATA TYPES, C++

Data Types
In programming, information are stored in computer memory with different data types. They are used for define what type of variables are used in a programming. Variables are nothing but reserved memory location to store values. 

C++ support large number of data types. Data type is the type of value (data) stored by a variable. C++ provides a predefined set of data types for handling the data is uses. Data can be of many types such as character, integer, real etc. Since the data to be dealt with are of many types, a programming language must provide different data types. In C++ data types are of two types, Fundamental Data Types and Derived Data Types.

Fundamental Data Types
As the name suggests these are the fundamental data types in C++. Fundamental data types are :
  • Character Data Type
  • Integer Data Type
  • Floating-Point Data Type
Character Data Type: The character data type is used to store characters, small integer and punctuation mark - typically ASCII characters but not always. "char" keyword is used to declare these type of variable. Each character is enclosed in single quotes. The signed range of char data is -128 - 127 and the unsigned range between 0-255. Character data type's size is one byte.

Integer Data Type: The integer data type is used for storing whole numbers. We can use signed, unsigned or plain integer values. The range of values for this type will be defined by compiler, normal range is -32768 - 32767, and size is 2 bytes. "int, short / long" keyword is used to declare these type of variable. C++ provide nine built-in integer data type. They are follows.

TYPE
SIZE(Bytes)
RANGE
int
2
-32768 to 32767
unsigned int
2
0 to 65535
signed int
2
-32768 to 32767
short int
2
-32768 to 32767
unsigned short int
2
0 to 65535
signed short int
4
-32768 to 32767
long int
4
-2147483648 to 2147483647
unsigned long int
4
0 to 4294967295
signed long int
4
-2147483648 to 2147483647

Floating-Point Data Types: A number having fractional part is a floating point number. An identifier declared as "float or double". Floating point variable represent real numbers. They can represent a much greater range of values. These are three sizes, float, double and long double.

TYPE
SIZE(Bytes)
RANGE
float
4
3.4E-38 to 3.4E+38
double
8
E-7E-308 to 1.7E+308
long double
10
3.4E-4932 to 1.1E+4932

Derived Data Types

These are the data types which are derived from the fundamental data type. It further divided into two categories, Built-In and User-Defined. Built in data types are array, function, pointer, reference and constant. User defined data types are class, structure, union and enumeration.

Built-In Derived Data Types

Arrays: Arrays refers to a list of finite number of same data types. Array is a collection of data element in which all element are same data type hence homogeneous data. An array is a series of elements of the same data type place in contiguous memory locations that can be individually referenced by adding an index to a unique identifier. The data in the array can be accessed by an index number ranging from 0 to n, where n is the number of data element in can store.

Pointer: A pointer is a variable that holds the memory address of other variable. It is also of different data types. Pointers provide indirect access to values

User Defined Derived Data Type

C++ allows user to define new type of data types based on the other existing data types. Fundamental data types are directly recognised by the C++ compiler. 

Class: A class is a collection of variables and functions under one reference name. It is the way of separating and storing similar data together. A class is a collection of a fixed number of components (members). A class definition begin with the keyword 'class'. The body of the class is contained within the set of braces. ({};). Member functions are often the means of accessing, modifying and operating the data members(i.e. variables). It is one of the most important features of C++ since OOP is usually implemented though the use of classes.

Structure: In C++ structure and class are same except for some very minor differences. A structure is a collection of variables which can be same or different data type under a single name 

Union: A union is a user defined data type or class type, that at any given time, contains only one object from the list of members. A union is a memory location shared by two or more different variables, generally of different types.

Enumeration: Enumeration is a user defined data type. It can be used to assign names to integer constants. Enumeration are declared by the keyword 'enum'.

Each topic will discuss detail. 

0 comentários:

Post a Comment

Blog Archive

Don't You Think this Awesome Post should be shared ??
| DATA TYPES, C++ |