Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Tuesday 7 November 2017

Data Types in C Language with Examples

Data Types in C Language

Now, Here we are going to discuss data types in c language with examples. 

Data type tell us which type of data or value we can store in a memory by the help of variables e.g integer type value, character type value, float type value, double type value, etc.

In other words, We can say that the data type is a keyword which identified the type of data and store the input of a program into a memory(Ram) by the help of variables.

For example: Declaration of data type

#include<stdio.h>
#include<conio.h>
void main()
{
int a = 50;
}

Here 'int' is a data type and 'a' is variable with value 50 of integer type. 


Data Types in C

There are different types of data types in c language which are given below.


Data Types in C Language

(1) Primitive or Primary Data Type

Some primitive data types which is int, char, float, double, and void.

(2) Derived Data Types

Some derived data types in c which is pointer, array, references, function.

(3) User - defined Data Types

Some user - defined data types in c which are structure, union, enumeration.


Primitive Data Types - Size and Range

The primitive data type contains integer and floating based data types. C language supports both signed and unsigned literals.

Let's understand first signed and unsigned then size and range of primitive data types.

Signed  : Signed keyword allows both negative and positive values and this is the default properties or data type modifier for every data type.

For example: 

#include<stdio.h>
#include<conio.h>
void main()
{
int a = 20;
int b = - 30;
signed int c = 40;
signed int d = - 50
}

Above all the data types declaration are valid declaration.

Unsigned : Unsigned keyword allows only positive value, It does not supports negative values.

For example:

#include<stdio.h>
#include<conio.h>
void main()
{
unsigned int b = 30;//valid declaration
unsigned int c = - 30;//invalid declaration 
}

The memory size of primitive data types can be change according to 16 or 32 or 64 bit operating system.

Data Type                         Memory Size               Range
char                                  1 byte                          - 128 to 127
signed char                      1 byte                          - 128 to 127
unsigned char                  1 byte                          0 to 255
short                                 2 byte                          - 32,768 to 32,767
signed short                     2 byte                          - 32,768 to 32,767
unsigned short                 2 byte                          0 to 65,535
int                                     2 byte                           32,768 to 32,767
signed int                         2 byte                           32,768 to 32,767
unsigned int                     2 byte                           0 to 65,535
short int                           2 byte                            32,768 to 32,767
signed short                     2 byte                            32,768 to 32,767           
unsigned short int           2 byte                             0 to 65,535
long int                             4 byte           - 2,147,483,648 to 2,147,483,647
signed long int                 4 byte           - 2,147,483,648 to 2,147,483,647
unsigned long int             4 byte           0 to 4,294,967,295
float                                  4 byte
double                               8 byte
long double                       10 byte

This is the table of data types in c with size and range.


Declaration of some data types with variables

#include<stdio.h>
#include<conio.h>
void main()
{
int a = 50;//positive integer data type
int aa = -48;//negative integer data type
char c = 'b'
float f = 3.1;
float ff = - 5.8
long l = 56850;
long ll = - 452658;
short s = 569;
short ss = - 569;
double d = 3.247895233
}


Data Types in Programming

This is simple c program where we will declare integer data type with variable and store value and print that value to console.

#include<stdio.h>
#include<conio.h>
void main()
{
int i = 7009;//integer data type with i variable
clrscr();
printf("Number is : %d ", i);
getch();
}

Output: 7009


Usage of sizeof Operator 

By using sizeof operator you can get size of type e.g int, char, float, etc.

For example:

#include<stdio.h>
#include<limits.h>
int main()
{
printf("Storage size for int : %d ", sizeof(int));

return 0;
}


Here we have learned data types in c language with examples.

Share:

1 comment:

  1. Very informative blog!

    Please take some time to visit my blog @
    Data Types

    Thanks!

    ReplyDelete

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate