Data Types in C

Data types are the type of data stored in a C program. Data types are used while defining a variable or functions in C. It’s important for the compiler to understand the type of predefined data it is going to encounter in the program. In this article, we will discuss Data type in C programming with example.


What is Data Type in C?

C provides several built-in data types, such as integer (int), character (char), floating-point (float), and double-precision floating-point (double), among others. Each data type has its own set of possible values and operations that can be performed on it.

Example Of Data Types In C

Let’s consider a scenario of a company. A company stores various data of their employee such as Name, Employee ID, Age, Salary, Address, Phone No, etc.

Now, these data are values containing alphabets, numbers, etc, so to make the processing of these huge data for programs easy, the information was categorized into different types:

Name: String
ID: Integer
Salary: Float or Double
Phone No: String 

Types Of Data Types In C

There are majorly five main categories of Data Type in C:

Data Type: Example of Data Type
Primary Data Type: Integer, Floating-point, double, string.
Derived Data Type: Union, structure, array, etc.
Enumerated Data Type: Enums
Void Data Type: Empty Value
Bool Type: True or False

Primary Data Types In C

The C programming language has five primitive or primary data types. 

1. Integer (int): Refers to positive and negative whole numbers (without decimal), such as 10, 12, 65, 3400, etc.

Example:
#include <stdio.h>   
void main() 
 int i = 5; 
 printf("The integer value is: %d \n", i); 

2. Character (char): Refers to all the ASCII character sets within single quotes such as ‘a’, ‘A’, etc.

Example:
#include <stdio.h>   
void main() 
 char c = 'b'; 
 printf("The character value is: %c \n", c); 
}

3. Floating-point (float): Refers to all the real number values or decimal points, such as 3.14, 10.09, 5.34, etc.

Example:

#include <stdio.h>   
void main() 
{
 float f = 7.2357; 
 printf("The float value is: %f \n", f); 

4. Double (double): Used when the range exceeds the numeric values that do not come under either floating-point or integer data type. 

Example:
#include <stdio.h>   
void main() 
 double d = 71.2357455; 
 printf("The double value is: %lf \n", d); 

These data types require specific keywords to define them:

Keyword Used <-----> Data Type

int : Integer
float  : Floating-point
double : Double
char : Character
void : Void


Comments