Articles added in Mathematics Lab | Cyber Lab is now open | Astronomy Lab is now open | VLSI Lab is now open | 120 SEO Tips article published | More exciting articles coming soon!




Datatypes in C++

Data types are used for declaring variables in C++. Variables helps building functions. And functions together builds up a program. The values of variables are stored somewhere in an unspecified location in the computer memory as binary (zeros and ones).

Our program does not need to know the exact location where a variable is stored; it can simply refer to it by its name. What the program needs to be aware of is the kind of data stored in the variable. We use numbers, alphabets and yes-no decisions. All these data belongs to a different set. There are four basic data types:


1. int:

int represents an integer value.
  1. Memory: 2 bytes
  2. Range: -32768 to 32767
For e.g. 45, 232, -421, etc.


2. float:

float represents a floating point or a single precision real number. It can be represented in two ways:
  1. Decimal form
  2. e.g. 10.124500, 3.141600, 1.41400, 2.000000
  3. Exponential form
  4. e.g. 8.85E-12 or 8.85e-12 which means 8.85x10^-12 .
    1.23E+2 or 1.23e+2 which means 1.23x10^2

Precision: 6 digits after decimal point.
Memory: 4 bytes.
Range: 3.4x10^-38 to 3.4x10^+38


3. double:

double represents double precision real number.
Like float, it can be represented in decimal as well as exponential form.

Precision: 14 digits after decimal point.
Memory: 8 bytes.
Range: 1.7x10^-308 to 1.7x10^+308


4. char:

char represents character.
Each character represents a unique numeric code. This coding scheme is known as ASCII (American Standard Code for Information Interchange) coding scheme.
In this scheme the code for A is 65 and a is 97. Starting code is 0 and last 255.

Memory: 1 byte.
Range: 256 characters.
e.g. 4, d, D, +, ?, :, etc.





Qualifiers or modifiers:

These are the keywords that can be used to create new data types using existing ones. There are four qualifiers:
  1. signed
  2. unsigned
  3. short
  4. long

note When we declare variables using these new data types, if a basic data type are omitted after a qualifier then 'int' will be assumed by the compiler.
e.g. long b means long int b.

Size and range of basic C++ datatypes are as shown in table:

Variable Declaration

All variables must be declared before they are used in instructions of a program.

Syntax:
datatype variable1, variable2, variable3,...;

e.g. int a,b,d;
float e1;
A variable can also be initialized at the time of declaration.
e.g. int a=5, b=10;














CACKLE comment system





Programming Resources
Computer Networking Fundamentals Android Application