Skip to main content

Unary operators in C

Short answer

Unary operators operate on a single operand. They include unary +/-, ++, --, !, ~, &, *, sizeof, and type cast. The term unary means 'one' because they require only one operand, unlike binary operators.

What are unary operators in C? Why are they named so?

Unary operators are operators that work on a single operand. They are called "unary" because uni means one: they need only one operand, unlike binary operators (a + b) which need two.

OperatorMeaningExample
+ , -unary plus / minus-a
++ , --increment / decrement++a, a--
!logical NOT!a
~bitwise complement~a
&address of&a
*value at address (pointer)*p
sizeofsize in bytessizeof(a)
(type)type cast(float)a
#include <stdio.h>
int main(void)
{
    int a = 5, b;
    b = -a;
    printf("%d %d\n", b, +a);
    printf("%d\n", !a);
    printf("%d\n", ++a);
    printf("%d\n", a--);
    printf("%d %d\n", a, (int)sizeof(a));
    return 0;
}

Output:

-5 5
0
6
6
5 4

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 3 questions →