198k views
3 votes
write a C program the prints out the size of variables with the following C data types- int, long, unsigned, long long, double, float, char, and double

User Pazof
by
6.8k points

1 Answer

2 votes

C program for finding size of different data types

#include <stdio.h>

//driver function

int main()

{

int a; //declaring a of type int

float b; //declaring b of type float

double c; //declaring c of type double

char d; //declaring d of type char

long e; //declaring e of type long

long long f; //declaring f of type longlong

unsigned g; //declaring g of type unsigned

// Sizeof operator is used to evaluate the size of a variable

printf(" int data type contains: %lu bytes\\",sizeof(a));/*Finding size of int */

printf("float data type contains : %lu bytes\\",sizeof(b));/*Finding size of float */

printf("double data type contains: %lu bytes\\",sizeof(c));/*Finding size of double */

printf("char data type contains: %lu byte\\",sizeof(d));/*Finding size of char */

printf("long data type contains: %lu byte\\",sizeof(e));/*Finding size of long*/ printf("longlong data type contains: %lu byte\\",sizeof(f));/*Finding size of longlong */

printf("unsigned data type contains: %lu byte\\",sizeof(g)); /*Finding size of unsigned */

return 0;

}

Output

int data type contains: 4 bytes

float data type contains : 4 bytes

double data type contains: 8 bytes

char data type contains: 1 byte

long data type contains: 8 byte

longlong data type contains: 8 byte

unsigned data type contains: 4 byte

User Harshit Rastogi
by
6.8k points