AnkitWebLogic

Example: sizeof Operator

Example 1: WAP to explain the use of sizeof() operator. 1

#include<stdio.h>
void main()
{
	int a=100;
    double b;
    printf("\nSize of a = %d",sizeof(a));
    printf("\nSize of b = %d",sizeof(b));
    printf("\nSize of 123L = %d",sizeof(123L));
    printf("\nSize of 123.45 = %d",sizeof(123.45));
    printf("\nSize of 123.45f = %d",sizeof(123.45f));
    printf("\nSize of short = %d",sizeof(short));
    printf("\nSize of int = %d",sizeof(int));
    printf("\nSize of long = %d",sizeof(long));
    printf("\nSize of char = %d",sizeof(char));
    printf("\nSize of float = %d",sizeof(float));
    printf("\nSize of double = %d",sizeof(double));
}
Output in Turbo C++:
Size of a = 2
Size of b = 8
Size of 123L = 4
Size of 123.45 = 8
Size of 123.45f = 4
Size of short = 2
Size of int = 2
Size of long = 4
Size of char = 1
Size of float = 4
Size of double = 8
Output in VS Code:
Size of a = 4
Size of b = 8
Size of 123L = 4
Size of 123.45 = 8
Size of 123.45f = 4
Size of short = 2
Size of int = 4
Size of long = 4
Size of char = 1
Size of float = 4
Size of double = 8
Online C Compiler:
Size of a = 4
Size of b = 8
Size of 123L = 8
Size of 123.45 = 8
Size of 123.45f = 4
Size of short = 2
Size of int = 4
Size of long = 8
Size of char = 1
Size of float = 4
Size of double = 8