Data Types in C Programming

Data Types in C Programming post thumbnail image

In this post, we will understand the use of data types in C programming as well as talk about the types of data types (primitive data types and derived data types).

Data Types This is such a topic of C programming, on which if we start talking in detail, then perhaps our talks will never end.

Now because we do not want to make this tutorial too lengthy, we will try to cover all the important points of C Data Types in minimum words.

In programming, both data types and variables are related topics, that is, first read about C data types or there is always confusion about C variables.

That’s why I would suggest you that after reading this tutorial, when you read the next tutorial C variables, after reading it completely, read this tutorial through so that you can understand well what are C data types.

Table of Contents

Data Types in C – What is C Data Types?

In a C program, you need different types of data such as someone’s age (20), someone’s name (“Praveen”), someone’s height (5.9) or someone’s gender (‘M’ or ‘F’).

All these values ​​​​( 20, “Praveen”, 5.9, ‘M’, ‘F’ ) are called data in programming and as you can see these are all different types of data such as age is the integer number and gender is the character value.

Different types of predefined data types have been given to handle (use) different types of data in C programming.

How many types are there in C Data Types?

When you find the answer of how many types of C data types are there, then you may get different answers in different places (books, websites).

According to what I found out in my research, there are two types of data types in C programming. Whose information I have given below.

Type of Data Types

Primitiveint, char, float, void
Derived (User Defined) or Non PrimativeArray, String, Structure, Union, Pointer, Function, typedef, enum
Data Types in C Programming

1. C Language Primitive Data Types

Data Types in C Programming
Data Types in C Programming

Primitive data types are also called primary data types, fundamental data types, built-in data types or basic data types, now it is your choice what you will call it.

Primitive data types are also mainly of 4 types int, char, float and void. We use all these in variable declaration, function return type etc.

Before understanding in details about int, char, float and void, you should understand about Sign Qualifiers. C primitive data types have 2 sign qualifiers signed and unsigned

Both these sign qualifiers are used only with int and char data types. If you do not use any sign qualifiers with these data types, then by default they are considered as signed data types.

Signed data types have both positive and negative numbers in their data range, but unsigned data types have only positive numbers in their data range.

Unsigned data types also have the advantage that the programmer has to confirm that the number is positive. Let us now understand about the four data types of primitive.

You can also read: Keywords and Identifiers in C Programming

Integer Data Types (int, short, long)

If there are any data types that are most used in C programming, then they are integer data type. These data types are used for whole numbers ( -245, -8, 0, 5, 468, 25450 ).

As you know integers are numbers without decimal value. int, short, long keywords (data types) are used to represent Integer data types in c programming.

If understood in more detail, then short and long are called size qualifiers of int data type, that is, you can say that both short and long are subtypes of int data type.

These three data types are used to represent interger numbers, but the difference between the three is the number range and memory size.

As the number range to hold integer value of int data type is more than short data type and hence int data type also occupied more space in memory.

The most interesting thing about C programming is that the size of data types is machine dependent, so the range of data types can also be different in different computers.

Float Data Types (float, double, long double)

Float data types are used for real numbers ( 95.67, 255.5225, 25450.74554001 ) ie for decimal numbers.

If you hold a real number such as 95.562 in int data type, then by removing the decimal part from this number, it will hold only 97, so for real numbers we use float data types.

To represent float data types in c programming, float, double, long double keywords (data types) are used.

These three data types are used to represent real numbers, but the difference between the three is the number range and memory size.

As the number range to hold the value of float data type is less than long data type, similarly the range of long is longer than long double and hence long double data type also occupied more space in memory.

In this way, the type of data we have to store, based on the range of data of that type, we decide which data type we want to use.

Character Data Type (char)

The char keyword (data type) is used for character data types such as ‘a’, ‘R’, ‘p’, ‘#’, ‘Z’. The char data type variable can store only one character at a time.

void data type

As you know, void means “nothing” or “no type”. You cannot use void data type with variable. The void data type is mostly used instead of function return type.

If the return type of a function is void, it means that it will not return the value of the data type in any way.

When you will read about functions and pointers then you will be able to understand void data type better.

Now that we have read about all primitive data types, so I have given a table below in which range, size and format specifiers of all primitive data types have been given.

TypeSize (bytes)RangeF. S.
int4-2,147,483,648 to 2,147,483,647%d
unsigned int40 to 4,294,967,295%u
short2-32,768 to 32,767%d
unsigned short20 to 65,535%u
long4-2,147,483,648 to 2,147,483,647%d
unsigned long40 to 4,294,967,295%u
char1-128 to 127%c
unsigned char10 to 255%c
float41.2E-38 to 3.4E+38 (6 decimal places)%f
double82.3E-308 to 1.7E+308 (15 decimal places)%lf
long double103.4E-4932 to 1.1E+4932 (19 decimal places)%Lf
Data Types in C Programming

2. C Language Derived or User Defined Data Types

Those data types which are defined by the user (programmer) with the help of one or more primitive data types are called user defined data types or derived data types.

Programmers use derived data types to meet the requirements of their program and to increase the readability of the program.

Array, String, Structure, Pointers, Function these are the most common derived data types, you will read about them in the upcoming tutorials.

I hope that you have liked this post. If you liked the post, then please share it with your friends and relatives and you can send your suggestion in the comment box below or email me at praveen171086@gmail.com.

You can also visit my Hindi YouTube Channel.

mm
Avinash Singh

I am Avinash Singh, a software engineer from the profession and have been working in the IT industry since 2009. I live in Barabanki district of Uttar Pradesh in India and completed intermediate in 2001 from Ram Sevak Inter College, a UP Board school. After inter I completed my professional degree (BCA & MCA) from Indira Gandhi National Open University, Delhi in 2008 and along with it I did many certifications to keep my knowledge up to date and the next year I started a software development company E – Vision Technocraft Pvt Ltd.

Leave a Reply

Your email address will not be published.

Related Post