Examples of Calculating Size of Data type

Size of Data Types

In C, each data type has a unique set of operations that can be done on it and varied memory requirements. The type of data that the variable can store, such as character, integer, float etc.

Examples of Calculating Size of Data type

Classification of Data Types in C:

Types Illustration
Primitive Data Type Primitive data type are used as a most fundamental data type in programming languages. Examples of primitive data type are as byte, character, sort, int, boolean, long, float and double.
User Defined Data Type A user defined data type is a data type that can be derived from an existing data type.Examples of user derived data types are as array, pointer, structure and union.
Void Data Type A void data type is a data type that hasn’t any value or operator and it doesn’t give any response to its caller. A void data type comes from primitive data type.
Derived Data Type A derived data type is a data type that derived from built-in or primitive data types.

Size of Data Types

Data Types Size (in bytes)
Int 4
Char 1
Float 4
long 4
Short 2
Double 8

Problem 1

Write a program to calculate the size of integer type data.

Run
#include<stdio.h>
int main()
{
	int size_of_int=sizeof(int);
	printf("The size of int data type = %d\n",size_of_int );
return 0;
}

Output:

The size of int data type = 4

Problem 2

Write a program to calculate the size of character type data.

Run
#include<stdio.h>
int main()
{
	int size_of_char=sizeof(char);
	printf("The size of char data type = %d\n",size_of_char );
return 0;
}

Output:

The size of char data type = 1

Problem 3

Write a program to calculate the size of float type data.

Run
#include<stdio.h>
int main()
{
	int size_of_float=sizeof(float);
	printf("The size of float data type = %d\n",size_of_float );
return 0;
}

Output:

The size of float data type = 4

Problem 4

Write a program to calculate the size of long type data.

Run
#include<stdio.h>
int main()
{
	int size_of_long=sizeof(long);
	printf("The size of long data type = %d\n",size_of_long );
return 0;
}

Output:

The size of long data type = 8

Problem 5

Write a program to calculate the size of short type data.

Run
#include<stdio.h>
int main()
{
	int size_of_short=sizeof(short);
	printf("The size of short data type = %d\n",size_of_short );
return 0;
}

Output:

The size of short data type = 2

Problem 6

Write a program to calculate the size of double type data.

Run
#include<stdio.h>
int main()
{
	int size_of_double=sizeof(double);
	printf("The size of double data type = %d\n",size_of_double );
return 0;
}

Output:

The size of double data type = 8

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription