Data Types In C : Learn C Data Type with Examples

Eitworld
4 min readJan 29, 2018

--

C Data type:

C Data Types determine the type of value stored in any variable or constant. In simple words, what kind of value is hold by the variable? Data types in C Language are as shown in the following table:

Generally Datatypes in C Language are Primitive data type which contains char, unsigned char, short, unsigned short, int, unsigned int, long, unsigned long, float, double, long double.

Derived data type which contains array, structure, union etc.

Enumerated data types is also called as user defined data types declared using enum keyword.

Data Types In C, basic data types are based on the integer and each and every data type has its own range and capacity or size so that they can contain their sized value. The following table shows the size and range of the basic data types.

1)Basic or primitive data type: The data types which are predefined in the C language is called as basic data type in C which are used to define the type of value stored in any variable, constant or array.

The primitive data types in C language are as follows:

1) Integer data type: it is used to store integer values. C language having integer type data types like short (signed), int (signed) , unsigned short, unsigned int, long(signed), unsigned long.

2) Character data type: this is used to store a single character. C language having two types of character data type char (signed char) and unsigned char.

3) Floating point data type: Floating point data type means value with floating point values. C language provides various floating point data type float, double, long double etc.

First we will see the size and range of the char type data type which are as follows:

Now we will see the size and range of the short data type which are as follows:

Now we will see the size and range of the int data type which are as follows:

Now we will see the size and range of the short int data type which are as follows:

Now we will see the size of the long int data type which are as follows:

Now we will see the size of the floating point data type which are as follows:

Here we have one summarized table which will show you the proper size and range and also show you the format string which is used with the corresponding data types. These all things are displayed in the following table:

According to compiler means by bit version the size and range can be varied from system to system.

2) Derived data type

The data types which are composed from the primitive data types are known as Derived data types which can be array, structure, union etc.

3) Enumerated data type

Enumerated data types are also called as user defined data types.

Enumerated data types are declared by using the enum keyword.

It is used to arrange a list of items in a sequence and is used for the fixed sequence. We can use the following syntax to declare the enumeration as follows:

enum idenitifer{list of items);

Here an example of enum having the list of seven days of a week:

enum week { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};

C Data Type with Examples; now we will see the example of data type how we can use these data types in suitable manner which are as follows:

#include<stdio.h>

#include<conio.h>

void main()

{

enum week { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};

printf(“\nSunday=%d”,Sunday);

printf(“\nMonday=%d”,Monday);

printf(“\nTuesday=%d”,Tuesday);

printf(“\nWednesday=%d”,Wednesday);

printf(“\nThursday=%d”,Thursday);

printf(“\nFriday=%d”,Friday);

printf(“\nSaturday=%d”,Saturday);

}

Output

Sunday=0

Monday=1

Tuesday=2

Wednesday=3

Thursday=4

Friday=5

Saturday=6

For more information visit: http://www.eitworld.com/cprogramming/c-data-types.php

--

--