C program to print size of variables using sizeof() operator.

sizeof() is an operator in c programming language, which is used to get the occupied size by the variable or value. This program demonstrate the example of sizeof() operator by printing size of different type of variables.

sizeof() operator example program

/*C program to print size of variables using sizeof() operator.*/
 
#include <stdio.h>
 
int main()
{
     
    char    a       ='A';           
    int     b       =120;
    float   c       =123.0f;
    double  d       =1222.90;
    char    str[]   ="Hello";
 
    printf("\nSize of a: %d",sizeof(a));
    printf("\nSize of b: %d",sizeof(b));
    printf("\nSize of c: %d",sizeof(c));
    printf("\nSize of d: %d",sizeof(d));
    printf("\nSize of str: %d",sizeof(str));
 
    return 0;
}

Output

Size of a: 1
Size of b: 4
Size of c: 4
Size of d: 8
Size of str: 6

C Basic Programs »


Related Programs

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.