Recently MeroSpark is lunched with more features and services, now you can ask your question, sell your books, share your notes and many more. Visit now and create your account to take full advantage of MeroSpark.

Data types in C++ | Object Oriented Programming (OOP)

Download our Android App from Google Play Store and start reading Reference Notes Offline.

data types in C++Data types in C++
Object Oriented Programming(OOP)
Third Semester | Second year
BSc.CSIT | Tribhuvan University (TU)

Data type in C++
In C++ programming, we store the variables in our computer’s memory, but the computer has to know what kind of data we want to store in them. The amount of memory required to store a single number is not the same as required by a single letter or a large number. Further, interpretation of different data is different inside computer’s memory.

The memory in computer system is organized in bits and bytes. A byte is the minimum amount of memory that we can manage in C++. A byte can store a relatively small amount of data: one single character or a small integer. In addition, the computer can manipulate more complex data types that come from grouping several bytes, such as long numbers or non-integer numbers.
Data types in C++ is used to define the type of data that identifiers accepts in programming and operators are used to perform a special task such as addition, multiplication, subtraction and division etc of two or more operands during programming. C++ supports a large number of data types. Data types can be categorized into three types which are described below;

Built-in Data Types
There are four types of built-in data types and let us discuss each of these and the range of values accepted by them one by one.

  • Integer data type (int):
    An integer is an integral whole number without a decimal point. These numbers are used for counting. For example 46, 167, -223 are valid integers. Normally an integer can hold numbers from -32768 to 32767. The int data type can further categorized into short, long and unsigned int.
    The short int data type is used to store integer with a range of -32768 to 32767, However, if the need be a long integer (long int) can also be used to hold integers from -2,147,483,648 to 2,147,483,648. The unsigned int can have only positive integers and its range lies up to 65536.
  • Floating point data type (float):
    A floating point number has a decimal point. Even if it has an integral value, it must include a decimal point at the end. These numbers are used for measuring quantities. Examples of valid floating point numbers are: 35.5, -66.3, and 49.07.
    A float type data can be used to hold numbers from 3.4*10-38 to 3.4*10+38 with six or seven digits of precision. However, for more precision a double precision type (double) can be used to hold numbers from 1.7*10-308 to 1.7*10+308 with about 15 digits of precision.
  • Void data type:
    It is used for following purposes;

    • It specifies the return type of a function when the function is not returning any value.
    • It indicates an empty parameter list on a function when no arguments are passed.
    • A void pointer can be assigned a pointer value of any basic data type.
  • Char data type:
    It is used to store character values in the identifier. Its size and range of values is given in table below;
Name Description Size* Range
Char Character or small integer 1 byte signed: -128 to 127

unsigned: 0 to 255

short int (short) Short Integer. 2 bytes signed: -32768 to 32767

unsigned: 0 to 65535

int Integer 4 bytes signed: -2147483648 to 2147483648

unsigned: 0 to 4294967295

long int (long) Long Integer 4 bytes signed: -2147483648 to 2147483648

unsigned: 0 to 4294967295

Bool Boolean value. It can take one of two values: true or false 1 byte true or false
float Floating point number. 4 bytes +/- 3.4e +/-38 (~7 digits)
double Double precision floating point number. 8 bytes +/- 1.7e +/-308 (~15 digits)
long double Long double precision floating point number 8 bytes +/- 1.7e +/-308 (~15 digits)
wchar_t Wide character 2 or 4 bytes 1 wide character

Derived Data types
C++ also permits four types of derived data types. As the name suggests, derived data types are basically derived from the built-in data types. There are four derived data types. These are:

  • Array
  • Function
  • Pointer and
  • Reference

User Defined Data Types
C++ also permits four types of user defined data types. As the name suggests, user defined data types are defined are defined by the programmers during the coding of software development. There are four user defined data types. These are:

  • Structure
  • Union
  • Class, and
  • Enumerator
(Visited 7,133 times, 4 visits today)

Posted By : Digvijay | Comment RSS | Category : Third Semester
Tag :

Post a Comment

Your email is never published nor shared. Required fields are marked *


Wordpress DMCA
Community | Toolbar | Android App | Founder/Developer : Hari Prasad Chaudhary | CSIT Portal Manager : Digvijay Chaudhary