Operators in C-1
Operators in C-1
1.4 Increment
We use this operator to increment the overall value of any given variable by a value of 1.
Prefix Increment
The operator in this method precedes the given operand (Example, ++p). Thus, the value of
the operand gets altered before we finally use it.
int p = 1;
int q = ++p; // q = 2
Postfix Increment
The operator in this method follows the given operand (Example, p++). Thus, the value of the
available operand gets altered after we use it.
For instance,
int p = 1;
int q = p++; // q = 1
int r = p; // r = 2
1.5 Decrement
We use this operator to decrement the overall value of any given variable by a value of 1. We
can perform decrement using two major ways:
Prefix Decrement
The operator in this method precedes the given operand (Example, –p). Thus, the value of the
operand gets altered before we finally use it.
For instance,
int p = 1;
int q = –p; // q = 0
Postfix Decrement
The operator in this method follows the given operand (Example, p–). Thus, the value of the
available operand gets altered after we use it.
For instance,
int p = 1;
int q = p–; // q = 1
int r = p; // r = 0
1.6 Address of Operator(&)
This type of operator provides the user with the address of any variable. The address of
operator is used to return the address (memory address) of any variable.
1.7 Sizeof()
The function of the size of operator is to return the original size of the available operand in
terms of bytes.
2. Arithmetic operator
3. Relational operator
Operator Meaning
== Equal to
!= Not equal to
< Is less than
<= Is less than or equal to
>= Is greater than or equal to
> Is greater than
4. Logical operator
5. Assignment operator
6. Conditional operator
Expression1 ? expression2: expression3;
o If the expression1 results into a true value, then the expression2 will execute.
o If the expression1 returns false value then the expression3 will execute.
#include <stdio.h>
int main()
{
int age;
printf("Enter your age");
scanf("%d",&age);
(age>=18)? (printf("eligible for voting")) : (printf("not eligible for voting"));
return 0;
}
7. Bitwise operator
The bitwise operators are the operators used to perform the operations on the data at the bit-
level.