Operator in C Programming - II

sizeof operators(sizeof())

Sizeof operator is a unary operator which can be used to calculate size of the operand.The result of sizeof is of unsigned integral type which is denoted by sizeof(); . we can applied into datatype like integer and floating-point types, pointer types, or compound datatypes such as Structure, union etc.

Example

#include<stdio.h>
int main()
{
  int a=7;
  printf("size=%d",sizeof(a));
}

Output

size=2

Ternary Operator

A ternary operatr is the operator which is expessed as:

Syntax

condition1 ? excute1 : excute2;
It means if the condition1 is true then execute1 will execute else execute2 will execute.It works like like a if else condition.

Example

#include<stdio.h>
int main()
{
  int a=7,b=5,x;
  (a<b ? x=2 : x=7);
  printf("x=%d",x);
}

Output

x=7