Data types and Format specifier in C..

Q)What are the data types in C? why we use data types in C? Difference between data types and variables in the C programming language.


These are some basic questions you may have related to programming or data types in C. Let’s try to clear all your questions regarding data types.

Data types in C language.

Syntax for declaration of a variable with the data type.

datatype name_of_variable;

1 – Primary or Basic data types.

These are the fundamental data types in C which have four types namely int for integer, char for a character, float for a decimal number, string for the mixture of character and integer and void.

a – int data type – The int data type stores integer from -32768 to 32767 and occupies only 2 bits of memory. It can not store any number with a decimal. The format specifier of int data type is “%d”. Example of int data type – 

int a; where a is the variable which can have any value ranging between -32768 to 32767.

b – char data type-  the char data type is used to store a single character and occupies 4\1 bits of memory. The format specifier of the char data type is “%s”.Example of  char data type is

char a; where a is variable which can have any possible value of alphabet.

c – float data type – Float data type is used to store numbers with decimal values and it occupies 4 bits of memory. Format specifier of float data type is “%f”. Example of float data type –

float a; where a is variable which can have any value like 1.0002, 5.9,3 or any number with or without decimal.

d – string data type – String data type is used to store a group of alphabets or a mixture of alphabet and numbers. The format specifier of the string data type is “%s”. Example

float a; where a will equal to any sentence. 

e – void – void means nothing. It is used when a variable has no value.

2 – Derived data type.

The derived data type is like an extended form of primary data type they are derived from primary data type. Derived data type consists of arrays, unions, pointers, etc. we will study about derived data type later as it is a little bit advanced.

                                                 *Format specifier*

The format specifier is used to assigning a value to a variable that is entered by the user. Different data types have different format specifiers as mentioned above.

In this article, we have successfully understood the concept of data type in the next article we will discuss about functions in C.

Leave a comment