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()

sizeof() operator finds the size of a constant, variable or a data type. Size is in terms of bytes.

**Output may change depending upon the compiler.

Program

Output

 

#include<stdio.h>
int main()
{
int num1;
float num2;
char num3;
printf(“\n%d”,sizeof(num1)); 2
printf(“\n%d”,sizeof(num2)); 4
printf(“\n%d”,sizeof(num3)); 1
printf(“\n%d”,sizeof(double)); 8
printf(“\n%d”,sizeof(long double)); 10
printf(“\n%d”,sizeof(short)); 2
printf(“\n%d”,sizeof(23)); 2
printf(“\n%d”,sizeof(13L)); 4
printf(“\n%d”,sizeof(23.55)); 8
printf(“\n%d”,sizeof(23.55f)); 4
printf(“\n%d”,sizeof(23.55L)); 10
return(0);
}

 



2. Comma operator

This operator separates variables during variable declaration or separate multiple expressions in a line.

Program 

#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