Вы находитесь на странице: 1из 3

DATA TYPES IN “C”

Data types are the storage representation of the variables used in the program. Use of data
types specifies no. of bytes taken by any variable in the memory. In C there are 4 basic
types of data types –

1. Primitive Data type


2. Non-Primitive Data type
3. User-Defined Data type
4. Empty Data Type

Primitive Data Type –


It is also known as “Primary data type”. All C compilers support 4 fundamental
data types namely; integer, character, floating point & double precision floating point.

Integer types –
Integers are whole nos. with a range of value supported by a particular
machine. Generally, integer occupies one word of storage. It takes 2 bytes. If we
use 16-bit word length the size of integer value is limited to the range -32768 to
32767. Similarly, a 32-bit word length can store an integer ranging from
-2,147,483,648 to 2,147,483,647.

Character types –
A single character can be defined as a character type data. Characters are
usually stored in 8-bits of internal storage. Characters have values from -128 to
127 or from 0 to 255.

Floating Point types –


Floating point numbers are stored in 4 bytes or 32-bits, with 6 digits of
precisions. Floating point numbers are defined in C by the keyword ‘float’. A
‘double’ data type number uses 64-bits giving a precision of 14-bits.

Non – Primitive Data Type –


These are also known as Derived data type. It consists of arrays, structures and
unions.

Arrays –
Array is actually a collection of similar data type and memory for an array
is allocated on contiguous spaces.

Structures –
Structure is a collection of fields in which the fields may be same or of
different types.
User-Defined Data Types –
C support user-defined data types. Once a user-defined type has been established,
then new variables, array, structures etc. can be declared in the terms of this new data
type. In C language user-defined data types are: typedef & enum.

typedef –
typedef is an abbreviation used for “Type Definition”. Its purpose is to
redefine the name of an existing data type. This can be later used to
declare variables. Its general form is:
typedef standard-datatype userdefined-datatype.
Ex: (i) typedef int age;
int x;
age p,q,r,s;

Here, all the variables are holding integer value but age helps us to understand
that these 4 variables will hold age. It helps users debugging the program.

(ii) struct student


{
char name [30];
int roll_no;
float percent;
};
struct student s;

Using typedef:
struct student
{
char name [30];
int roll_no;
float percent;
};
typedef struct student STU;
STU s1, s2;

enum –
The enumerated data type gives us an opportunity to invent our own data
type and define what values the variables of this data type can take. Its general form is:
enum datatype-name {val1,val2,…..,valn};
Ex:-
(i) enum weekdays
{Sunday, Monday, Thursday, Wednesday, Thursday,
Friday, Saturday};

weekdays x, y;
(ii) enum marks
{
gradeA=1, gradeB=2, gradeC=3
};
enum marks s1, s2;

The values declared by enum are ordinal nos. Ordinal values starts from zero.

Empty Data Type –

The keyword void can be used as a type specifier, when defining a function that
does not return anything. The keyword void is the example of empty data type.
Ex: void main ()

Вам также может понравиться