45. WAP to understand [sizeof] operator.
#include<stdio.h>
void
main()
{
int part;
printf("Understand sizeof
operator\n");
printf("Enter part no : ");
scanf("%d",&part);
switch(part)
{
case 1:;
int i=0;
char ch='a';
float f=23.5;
double dd=45.5;
printf("%ld %ld
%ld\n",sizeof(i),sizeof(int),sizeof(10));
printf("%ld %ld
%ld\n",sizeof(ch),sizeof(char),sizeof('a'));
printf("%ld %ld
%ld\n",sizeof(f),sizeof(float),sizeof(23.5f));
printf("%ld %ld
%ld\n",sizeof(dd),sizeof(double),sizeof(45.5));
printf("%ld\n",sizeof("abc"));
break;
case 2:
if(sizeof(4)>-1)
printf("Yes\n");
else
printf("No\n");
break;
case 3:;
int a=2,b=4,c=0;
char d;
printf("BEFORE c =
%d\n",c);
printf("%ld\n",sizeof(c=a+b));
printf("AFTER c =
%d\n",c);
printf("%ld\n",sizeof(a+b));
printf("%ld\n",sizeof(d=a+b));
break;
case 4:;
char ch1='a',ch2='b',ch3;
printf("%ld\n",sizeof(ch1+ch2));
printf("%ld\n",sizeof(ch3=ch1+ch2));
break;
case 5:;
int o = 10;
double z = 1.2;
printf("%ld\n",sizeof(o+z));
printf("%ld\n",sizeof(o>z));
printf("%ld\n",sizeof(0x12));
printf("%ld\n",sizeof(012));
break;
}
}
Comments
Post a Comment