Data type

Data Type

  1. Data type is a finite set of values along with set of rules for different operations.
  2. Data is very important in terms of programming.
  3. Data structure is basically how data is stored and the different operations performed on that particular data.

Example :  Integer data type 5, -53 and 322 etc is integer data type and int keyword to define a integer data type in c .

 

Types of Data type in C

  1. Primary data types
  2. secondary data types
  3. user define data types
  4. void data types

 

  1. Primary data types :  It is basically the building blocks of the data structure.

Types of Primary data types

  • int  (integer 5, -8)
  • float (real number 32.77, -3.7)
  • char (characters A , Language)
Data type Bytes Range format
Short int or int 2 -32768 to +32767 %d
Signed short int or unsigned short int or Unsigned int 2 0 to 65535 %u
long int or signed long int ot long 4 -2147483648 to + 2147483647 %ld
Unsigned long int or unsigned long 4 0 to 4294967295 %lu

Float data type
The floating point data types consists of a subset of the real numbers.
Float are these values which have a decimal point.
Example : 5 is integer data type and 5.0 is floating point data type

Data type Bytes Range Format
int 4 -3.4e 38 to +3.4e 38 %f
double 8 -1.7e 308 to +1.7e 308 %lf
Long double 10 -1.7e 4932 to +1.7e 4932 %Lf

Character Data Type
The character data types are used to store the special characters and the alphabets.

Data Type Bytes Range Format
Signed char or char 1 -128  to +127 %c
Unsigned char 1 0 to 255 %c

Demonstration of Primary data types:

#include<stdio.h>
#include<conio.h>
Void main(){
char ch;
unsigned char u;
ch=’+’;
u=’B’;
clrscr();
printf(“ch=%c  and its ASCII value =%d”, ch, ch);
printf(“\n u=%c  and its ASCII value =%d”, u, u);
getch();
}

Secondary data types

  1. Arrays
  2. Structures
  3. Unions
  4. Pointers

User Defined Data types
Types of user Defined data types

  1. Typedef
  2. enum

Type def
Typedef provides us a short and meaningful way to call a data type

Example:

Struct student {
char name;
int roll_no;
int marks;
};

Now we can create object for above structure student
Struct  student s;

Enumerated data type
The enum data type is used to create our own data type and give it the values.

enum  class
{
BCA,  MSC, MCA
};

Void data type: It is also known as empty data type it is declared where no values is returned by the function.