sizeof() operator in C | comma operator in C | Special operators in C

sizeof() operator in C | comma operator in C | Special operators in C

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

  •  sizeof()
  •  Comma



1.  sizeof() operator in C

This operator returns the size of a variable, constant or data type in terms of bytes.

Program to demonstrate the use of sizeof() operator in C Language

#include<stdio.h>
int main()
{
int a;
float b;
char c;
printf("\n%d",sizeof(a));  /*4*/
printf("\n%d",sizeof(b));  /*4*/
printf("\n%d",sizeof(c));  /*1*/
printf("\n%d",sizeof(double));  /*8*/
printf("\n%d",sizeof(long double)); /*12*/
printf("\n%d",sizeof(short));  /*2*/
printf("\n%d",sizeof(123));  /*4*/
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)); /*12*/
return(0);
}

2. Comma operator in C 

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 in C.

#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.

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