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; }
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.
No comments:
Post a Comment