Sunday, 31 July 2016

Data types in c++

DATA TYPES

A data type determines the type and the operations that can be performed on the data.They are used to define types of variables and contents used . Data type define the way you use storage in the programs you write.C++ provides various data types and each data type is represented differently within the computer's memory. the various data types provided by C++ are BUILT-IN data types,DERIVED data types and USER-DEFINED data types as shown in figure .




BUILT-IN DATA TYPES


The basic (fundamental) data types provided by c++ are integral,floating point and void data type.Among these data types, the integral and floating-point data types can be preceded by several type modifiers.These modifiers(also known as type qualifiers ) are the keywords that alter either size or range or both of the data types .The various modifiers are short ,long,signed and unsigned .By default the modifier is signed.
In addition to these basic data types ,ANSI C++ has introduced two more data types namely,bool and wchar_t.
                                                                    OR
THESE ARE THE DATA TYPES WHICH ARE PREDEFINED AND ARE WIRED DIRECTLY INTO THE COMPILER.eg: int,char etc.



Integral Data Type :The integral data type is used to store integers and includes char (character) and int (integer) data types.

CHAR:Character refer to the alphabet ,numbers and other, characters (such as {,@,#,etc) defined in the ASCII character set .In C++, the char data type is also treated as an integer data type as the characters are internally stored as integers that range in value from -128 to 127. The char data type occupies 1 byte of memory (that is, it holds only one character at a time ).

The modifiers that can precede char are signed and unsigned .The various character data type with their size and range are listed in above table.

INT:Numbers without the fractional part represent integer  data . In C++ , the int data  type is used to store integers such as 4,42,5233,-55,-759. Thus,it cannot store numbers such as 4.29,-586,-65.2579.The various integer data types with their size and range are listed below



FLOATING-POINT DATA TYPE:A floating -point data type is used to store real numbers such as 3.98,12.345,0.25,-45.85.This data type includes float and double' data types. The various floating-point data types with their size and range are listed below.



VOID:The void data type is used for specifying an empty parameter list to a function and return type for a function . When void is used to specify an empty parameter list,it indicates tha a function does not take any argument and when it is used as a return type for a function , it indicates that a function does not return any value .For void, no memory is allocated and hence, it cannot be used to declare simple variables, however, it can be  used to declare generic pointers.

BOOL AND WCHA_T: The bool data type can be held only boolean values,that is;either true or false, where true represents 1 and false represents 0. It requires only one bit of storage ,however,it is also considered as an integral data type .The bool data type is mostly commonly used for expressing the result of logical operations performed on the data.It ia also used as a return type of a function indicating the success or the failure of the function.

In addition to char data type ,C++ provides another data   type wchar_pt which is used to store 16- bit wide characters.Wide characters are used to hold large character sets associated with some non-english languages.

DERIVED DATA TYPES: Data types that are derived from the built-in data types are known as derived data types .the various derived data types provided by c++ are arrays,junction,references and pointers . 
                                                                      
ARRAY: An array is a set of elements of the same data type that are referred to by the same name.All the elements in an array are stored at contiguous(one after another) memory locations and each  element is accessed by a unique index or subscript value. the subscript value indicates the position of in an array.

FUNCTION:A function is a self-contained program segment that carries out a specific well-defined task. In  C++, every program contains one or more funcyions which can be invoked from other parts of a program ,if required.

REFERENCE:A reference is an alternative name for a variable .that is ,a reference is an alias for a variable in a program .A variable and its reference can be used interchangeably in a program as both refer to the same memory locations . Hence, changes made to any of them (say,a variable) are reflected int the  other (on reference).

POINTER:A pointer is a variable that can store the memory address of another variable. pointers allow to use the memory dynamically. That is, with the help allocated of pointers , memory can be allocated or de-allocated to the variables at run-time , thus,making a program more efficient.

No comments:

Post a Comment