Thursday 3 January 2013

Data types in C


In C, variable(data) should be declared before it can be used in program. Data types are the keywords, which are used for assigning a type to a variable.

Data types in C

  1. Fundamental Data Types
    • Integer types
    • Floating Type
    • Character types
  2. Derived Data Types
    • Arrays
    • Pointers
    • Structures
    • Enumeration

Syntax for declaration of a variable

data_type variable_name;



Data Types in C :

"Data type can be defined as the type of data of variable or constant store."
When we use a variable in a program then we have to mention the type of data. This can be handled using data type in C.
Followings are the most commonly used data types in C.

KeywordFormat SpecifierSizeData Range
char%c1 Byte-128 to +127
unsigned char<-- -- >8 Bytes0 to 255
int%d2 Bytes-32768 to +32767
long int%ld4 Bytes-231 to +231
unsigned int%u2 Bytes0 to 65535
float%f4 Bytes-3.4e38 to +3.4e38
double%lf8 Bytes-1.7e38 to +1.7e38
long double%Lf12-16 Bytes-3.4e38 to +3.4e38

* QUALIFIER :

When qualifier is applied to the data type then it changes its size or its size.
Size qualifiers : short, long
Sign qualifiers : signed, unsigned

* ENUM DATA TYPE :

This is an user defined data type having finite set of enumeration constants. The keyword 'enum' is used to create enumerated data type.
Syntax:
enum [data_type] {const1, const2, ...., const n};

Example:
enum mca(software, web, seo);

* TYPEDEF :

It is used to create new data type. But it is commonly used to change existing data type with another name.
Syntax:
typedef [data_type] synonym;

OR

typedef [data_type] new_data_type;

Example:
typedef int integer;
integer rno;


No comments:

Post a Comment