In this tutorial you will learn about the C Program to find the size of int, float, double, and char and its application with practical example.
C Program to find the size of int, float, double, and char
In this tutorial, we will learn to create a C program that will Find the Size of int, float, double, and char in Your System using C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Arithmetic operations in C Programming.
What is a data type?
A data type, in every programming language, specifies which type of value a variable is going to hold in the program. i.e. integer, character, float, double.
Algorithm for the program to view data type size:-
1 2 3 4 5 6 7 8 9 10 11 |
1. Initiating the program 2. Using size of function to print the size of character data type. 3. Using size of function to print the size of integer data type. 4. Using size of function to print the size of float data type.. 5. Using size of function to print the size of double data type. 6. End program. |
Program to check the size of predefined data types in C programming.
In every programming language, there are many predefined datatypes available. Today we will create a program that will print the size of integer, character, float, and double in bytes. Because every datatype variable reserves the size in memory for each type of variable.
With the help of this program, we can find the size of the above data types.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include<stdio.h> int main() { //declaring the requireed variable for the program. int intType; float floatType; double doubleType; char charType; // sizeof for printing the size of data type integer printf("Size of int: %zu bytes\n", sizeof(intType)); // sizeof for printing the size of data type float printf("Size of float: %zu bytes\n", sizeof(floatType)); // sizeof for printing the size of data type double printf("Size of double: %zu bytes\n", sizeof(doubleType)); // sizeof for printing the size of data type character printf("Size of char: %zu byte\n", sizeof(charType)); return 0; } |
Output:-
Printing the size of character data type using the size of function.
Integer type printing its size by using sizeof function.
Printing the size of float data type using the size of function.
Printing the size of double data type using the size of function.