×

C Data type

Data Types in C with Examples

Data types are used to define the type of data that a variable can store to perform a specific operation.

ANSI C provides three types of data-types.
  1. Primary Data Types
  2. Derived Data Type
  3. User Defined Data Types
 

Primitive data types:
Void It holds no value and generally used with function.
Int It is used to denote an integer type.
Char It is used to denote a character type.
float, double It is used to denote a floating point type.
int *, float *, char * It is used to denote a pointer type.

Primitive data types are used to hold the maximum value. Every C compiler supports five primary data types:
Example:
int a=90;  //  valid
a=90;  //   invalid
Derived  Data Type: Derived data types are derived from fundamental data type.  Variable of derived data type allows us to store the value of the same time in one variable. C supports three derived data types:
Arrays Arrays are sequences of data items that have homogeneous values and adjacent memory locations to store values.
References Function pointers allow referencing functions with a particular signature.
Pointers It is used to access memory and deal with their addresses.

Example:
int mark[5]={10, 20, 30, 40};
int *a;
User Defined Data Types: The user-defined data type is used to store multiple values. There are various user-defined data types are given below in the table.
Data Types Description
Structure The structure is a package of variables under a single name. The “struct” keyword is used to define a structure.
Union It is used to store the various data types in the same memory location.
Enum It consists of integral constants and each of them is assigned with a specific name. It is defined as “enum” keyword.

Example:
struct student
{
int id;
char name[10];
float mob;
};
C Data Type with size
Let us consider an example to find the memory size of data type:
 
#include 
int main()
{
int a;
char b;
float c;
double d;
printf("Storage size for int data type:%d \n",sizeof(a));
printf("Storage size for char data type:%d \n",sizeof(b));
printf("Storage size for float data type:%d \n",sizeof(c));
printf("Storage size for double data type:%d\n",sizeof(d));
return 0;
}
Data Types 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 int 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 1E–37 to 1E+37 with six digits of precision
double 8 byte 1E–37 to 1E+37 with ten digits of precision
long double 10 byte 1E–37 to 1E+37 with ten digits of precision

Related Topics

Calendar application in C

Introduction to the calendar application We all are familiar with the calendar. It plays a crucial role in our daily life. We run toward the calendar whenever we want to know...

6 minutes read.

Armstrong program in C using function

In this article we will learn how to find Armstrong of a number using function in C. An Armstrong number is a three-digit number that is the sum of its separate...

1 minute read.

Ceil function in C

Introduction In the C Programming Language, the ceil function is a library function which is used to obtain the ceil value, i.e., it returns the smallest integer that is greater than...

4 minutes read.

Escape Sequence in C

An escape sequence is a sequence of character that used inside the string literal or character.  All the escape sequence is used with the backslash (\) symbol. The list of an...

1 minute read.

How to initialize array to zero in C

In this article, you will learn how to initialise an array to 0 in C In C, an array is declared as: char ZEROARRAY[2022]; The global scope changes at runtime to all zeros....

3 minutes read.

Pointer arithmetic in C

In the C programming language, a pointer is an address which stores a numeric value. Hence, a developer can perform several arithmetic operations on the same just as one does...

4 minutes read.

Reverse a Stack using Recursion in C

In this tutorial we will learn how recursion will be used in this case to reverse a stack. For loops, while loops, do-while loops, and similar constructions are not permitted....

5 minutes read.

Pascal Triangle in C

The pascal triangle in c is an array of binomial coefficients in triangular form. Here the nth row contains the binomial coefficient of ncr.In a pascal triangle, every number is...

2 minutes read.

gets() function in C

gets() is a pre-define or built-in function present in the stdio.h header file. stdio stands for standard input and output. gets() function is used to read a stream and store...

4 minutes read.

Armstrong Number in C

The Armstrong number is defined as the sum of each of its digits to the power of the number base for the each given number with any given number base....

3 minutes read.

Pointer in C

Pointer is a variable that is used to contain the address of another variable. We can easily create a pointer in C language. Example: int *ptr Symbol Description & (ampersand sign) Address of an operator...

1 minute read.

Floor() Function in C

Floor() function is a built-in function in C which is defined in the math.h header file. This function is used to return the nearest integer value which is less than...

4 minutes read.

Passing Array to Function in C

Need to pass Arrays? The need to pass arrays to a function arises when we need to pass a list of values to a given function. During the course of our programming...

4 minutes read.

Difference between C and Java

C programming and Java programming are two of the earliest programming languages. C programming follows a procedural approach whereas Java programming follows an object-oriented approach. Java programming is a part...

3 minutes read.

fflush in C

In this article, we will understand what is fflush(), the need for fflush and fflush(stdin), and fflush(stdout). The fflush() function is used to clear the output buffer and move the buffered...

3 minutes read.

Random function in C

Random function in C In the C programming language, the rand() is a function used for Pseudo Random Number Generator (PRNG). The random number generated by the rand() function is not...

4 minutes read.

Socket Programming in C

Socket programming is a process that connects the two or more nodes on a networking communication with respective to each other. One of the sockets that determines the socket (I.e.,...

5 minutes read.

Classification of Programming language

 Classification of Programming language  The programming language represents a set of instructions compiled along with each other to perform a specific task provided by the CPU (Central Processing Unit). A programming...

3 minutes read.

Infinite loop in C

Definition of infinite loop The infinite loop is a loop that does not get dismissed because of its looping construct. A continuous output or no output are the two possible outcomes...

3 minutes read.

Assignment Operator Program in C

An assignment operator is a symbol used to assign a value to a variable in a programming language. The assignment operator is often the equal symbol (=) in programming languages....

12 minutes read.