C Data Types


C Data types

-Data type is the description of nature of data either in numeric forms or in character form.
-Data types are the basic building of the C variables.
- Before declaring a variable its data type must be defined.
- Different compilers have different data types.

There are mainly five types of data types used in C compiler.

1. Primary or Scalar data type
2. Secondary data type
3. User defined or Enumerated or Typedef data type.
4. Empty data type or void data type.
5. Pointer data type

Following figure shows the different data types :











Primary or Scalar data type :

-This is used for representing a single value only.
-It is also called simple or fundamental data type.

These are sub-divided into four categories :

(a) Integer data type
(b) Float data type
(c) Double data type
(d) Character data type

(a) Integer data type :
  • It is of integral type.
  • It is without decimal point.
  • It can be signed or unsigned.
  • It can be of int, short int, long int.
  • Generally an integer occupies 2 bytes memory space and its
    value range limited to -32768 to +32767 (that is, -215 to +215-1) .
Memory allocation :






Syntax
:


int variablename;

like :

int num1;
short int num2;
long int num3;

Example: 5, 6, 100, 2500.

(b) Float data type :
  • This data type have atleast one digit with a decimal point.
  • It can also be signed or unsigned.
  • This is used to store fractional numbers (real numbers) with 6 digits of precision.
Memory Allocation :






Syntax:

float variable-name

like :

float num1;
double num2;
long double num3;

Example: 9.125, 3.1254.

(C) Double data type :
  • It has very large floating data, so are called large real numbers.
  • It have double precision value having the 64 bit size and higher range.
Syntax :

double variable-name;

(d) Character data type :
  • Character type variable can hold a single character.
  • It can be signed and unsigned chars; both occupy 1 byte each, but having different ranges.
  • Unsigned characters have values between 0 and 255, signed characters have values from –128 to 127.
Syntax: char variable name ;

like:

char ch = ‘a’;

Example: a, b, g, S, j.

The following figure shows the size of differeny data types :



















The following figure represents the range :

















Secondary Data types :

These include :

-Arrays :

An array in C language is a collection of similar data-type, means an array can hold value of a particular data type for which it has been declared. We will discuss arrays in arrays topic later.

-Unions :

We will discuss it in union topic later.

-Structures :

Another secondary datya type. These are very important as who has command over these can easily learn the Classes and objects concepts. We will discuss these in details later.


Void data type :


The void type has no values therefore we cannot declare it as variable as we did in case of integer and float.

The void data type is usually used with function to specify its type. Like in our first C program we declared “main()” as void type because it does not return any value.
The concept of returning values will be discussed in detail in the C function topic.


Enumerated data type :

We will study it in detail in the enumerated data types topic.

Pointer data type :

Pointers areused to handle the data at their memory location.
These are some complex that most find difficult to work with them.
We will discuss it in details later.



     Prev                                                   NEXT

0 comments:

Post a Comment