Q:

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

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now