The Special Operators are used for special functions in C programs. Some of the Special Operators available in C language are as follows:
1. sizeof() operator
The sizeof() operator is used to find out the size of the variables in C program. For example:
consider 'a' as an integer then
sizeof(a) would return 2 or 4 based on the compiler or system used
Program example of sizeof() operator
//An example of sizeof() operator
#include<stdio.h>
int main()
{
char a;
int b;
float c;
double d;
printf("size of char %lu\n",sizeof(a));
printf("size of int %lu\n",sizeof(b));
printf("size of float %lu\n",sizeof(c));
printf("size of double %lu\n",sizeof(d));
return 0;
}
Output
size of char 1
size of int 4
size of float 4
size of double 8
2. Reference operator
The reference operator is denoted by &
symbol. It is used to return the address of the variable. If x is a variable then &x will return the address of the x.
Program example of reference operator
//An example of reference operator
#include<stdio.h>
int main()
{
int a;
printf("address of a %p\n",&a);
return 0;
}
Output
address of a 0x7fff58dfcae8
3. Dereference operator
The dereference operator is also known as an indirection operator. It is denoted by *
symbol. It is used to return the value pointed by the pointer variable. If x is a pointer, then *x represents the value contained in the address pointed by x.
Program example of dereference operator
//An example of dereference operator
#include<stdio.h>
int main()
{
int a = 10, *x;
x = &a;
printf("value pointed by pointer x is %d\n",*x);
return 0;
}
Output
value pointed by pointer x is 10