sizeof() operator in C | comma operator in C

Preview

Special operators

There are many special operators provided by C language which are as follows:

  •  sizeof()
  •  Comma



1.  sizeof()

This operator is used to find the size of a variable, constant or data type. The size returned by this operator is in terms of bytes.

Program to demonstrate the use of sizeof() operator.

Output

(Line Wise)

#include<stdio.h>
int main()
{
int a;
float b;
char c;
printf(“\n%d”,sizeof(a));2
printf(“\n%d”,sizeof(b));4
printf(“\n%d”,sizeof(c));1
printf(“\n%d”,sizeof(double));8
printf(“\n%d”,sizeof(long double));10
printf(“\n%d”,sizeof(short));2
printf(“\n%d”,sizeof(123));2
printf(“\n%d”,sizeof(123l));4
printf(“\n%d”,sizeof(123.45));8
printf(“\n%d”,sizeof(123.45f));4
printf(“\n%d”,sizeof(123.45L));10
return(0);
}

 



2. Comma operator

This operator is used to separate variables from each other in variable declaration statement and to separate multiple expressions from each other in same line.

Program to demonstrate the use of comma operator.

#include<stdio.h>
int main()
{
int a,b,c;
c=(a=5,b=4,a+b);
printf(“\na=%d”,a);
printf(“\nb=%d”,b);
printf(“\nc=%d”,c);
return(0);
}
Output
a=5
b=4
c=9

Description:

In expression c=(a=5,b=4,a+b), a will be assigned value 5, b will be assigned value 4, then a+b will be evaluated to generate sum of 5 and 4 i.e. 9 which will be stored in variable c.



Lesson tags: comma opeartor in C, sizeof() operaor of C, special operators in c
Back to: C Programming Language