Slider

C Program to Find Size of int, float, char and double.

C program to find the size of different data types. Use the sizeof operator to determine the size of each data type and store the results in variables
In this C program, we will determine the size of various data types such as int, float, char, and double. The size of a data type represents the number of bytes it occupies in memory. We will use the sizeof operator to calculate the size of each data type.

Data Types


Steps to find the size of a data type:

Step 1: Declare variables of each data type (int, float, char, and double).
Step 2: Use the sizeof operator to determine the size of each data type and store the results in variables.
Step 3: Display the size of each data type in bytes.
Note%zu format specifier is used to print the result of the sizeof operator, which gives the size of a data type in bytes. (alert-passed)

C program to find the size of different data types. 

//C program to find size of data types
#include <stdio.h>

int main() {
    int intSize;
    float floatSize;
    char charSize;
    double doubleSize;

    // size of each data type
    printf("Size of int data type: %zu \n", sizeof(intSize));
    printf("Size of float data type: %zu \n", sizeof(floatSize));
    printf("Size of char data type: %zu \n", sizeof(charSize));
    printf("Size of double data type: %zu \n", sizeof(doubleSize));

    return 0;
}
Output:
Size of int data type: 4 
Size of float data type: 4 
Size of char data type: 1 
Size of double data type: 8 

In this program, we aimed to determine the size of different data types in C. The int and float data types occupy 4 bytes each, char occupies 1 byte, and double occupies 8 bytes. The size of data types may vary depending on the system architecture and compiler used.
0

No comments

Post a Comment

both, mystorymag

DON'T MISS

Tech News
© all rights reserved
made with by AlgoLesson
Table of Contents