sizeof() Operator | Sizes ,Precision and Range of different data types

sizeof() Operator

This operator is used to find out size of variables,structures ,pointers ,etc in bytes.

Program to understand sizeof() opertaor

#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
x=98;
clrscr();
y=sizeof(x); //size of variable
printf("%d",y);
getch();
}


NOTE - We will use this operator in further posts and program to understand it more.

Program to find out size, precision and range of different data types

#include<stdio.h>
#include<limits.h>
#include<float.h>
void main()
{
clsrcr();
printf("sizeof(char)=%u\n",sizeof(char));
printf("sizeof(short)=%u\n",sizeof(short));
printf("sizeof(int)=%u\n",sizeof(int));
printf("sizeof(long)=%u\n",sizeof(long));
printf("sizeof(float)=%u\n",sizeof(float));
printf("sizeof(double)=%u\n",sizeof(double));
printf("sizeof(long double)=%u\n",sizeof(long double));

printf("SCHAR_MIN= %d\n",SCHAR_MIN);
printf("SCHAR_MAX= %d\n",SCHAR_MAX);
printf("UCHAR_MAX= %d\n",UCHAR_MAX);
printf("SHRT_MIN= %d\n",SHRT_MIN);
printf("SHRT_MAX= %d\n",SHRT_MAX);
printf("USHRT_MAX= %d\n",USHRT_MAX);
printf("INT_MIN= %d\n",INT_MIN);
printf("INT_MAX= %d\n",INT_MAX);
printf("UINT_MAX= %d\n",UINT_MAX);
printf("LONG_MIN= %d\n",LONG_MIN);
printf("LONG_MAX= %d\n",LONG_MAX);
printf("ULONG_MAX= %d\n",ULONG_MAX);
printf("FLT_MIN= %d\n",FLT_MIN);
printf("FLT_MAX= %d\n",FLT_MAX);
printf("DBL_MIN= %d\n",DBL_MIN);
printf("DBL_MAX= %d\n",DBL_MAX);
printf("LDBL_MIN= %d\n",LDBL_MIN);
printf("LDBL_MAX= %d\n",LDBL_MAX);

/*Number of digits of precision*/
printf("FLT_DIG=%d\n",FLT_DIG);
printf("DBL_DIG=%d\n",DBL_DIG);
printf("LDBL_DIG=%d\n",LDBL_DIG);

getch();
}



Comments

Popular posts from this blog

Coding tips for Developers

Master Data Structure & Algorithms in Python

How to Start with Coding: A Beginner's Guide