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

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.

⚡ Please share your valuable feedback and suggestion in the comment section below or you can send us an email on our offical email id ✉ algolesson@gmail.com. You can also support our work by buying a cup of coffee ☕ for us.

Similar Posts

No comments:

Post a Comment


CLOSE ADS
CLOSE ADS