hamburger

What are Unary Operators in C?

By BYJU'S Exam Prep

Updated on: September 25th, 2023

Unary Operator in C operates on one operand only. An operator specifies the operation to be applied on operands to get the desired result. This single operand is the only input used to create a new value.

Unary Operators in C PDF

This article will discuss the meaning of unary operators in C, the types of unary operators in C, and the functions of unary operators in C. Before jumping onto the unary operators in C, let us first discuss what an operator means and the type of operators available in C.

Download Formulas for GATE Computer Science Engineering – Programming & Data Structures

What is an Operator?

An operator specifies the operation to be applied to its operands. An operand specifies an entity on which an operation is to be performed. An operand can be a variable name, a constant, a function call, or a macro name. The operators in C, as per the GATE CSE syllabus, are classified based on the following criteria:

  • The number of operands on which an operator operates.
  • The role of an operator.

Download Formulas for GATE Computer Science Engineering – Discrete Mathematics

What is a Unary Operator in C?

Based on the number of operands an operator operates in the C programming language, the operators are classified as unary, binary, and ternary. Let us discuss each one for the upcoming GATE CSE exam separately:

  • Unary Operator: A unary operator operates on only a single operand. For example, in the expression -8, “-“ is a unary minus operator as it operates on only one operand. The operand can be present towards the right of the unary operator. Example of unary operators are:- &(address-of operator), size of operator, !(logical negation), ~(bitwise negation), ++(increment operator), –(decrement operator), unary +, unary -, etc.
  • Binary Operators: A binary operator operates on two operands. It requires an operand on both sides that are left and right. For example, in the expression 3+9, “+” is a binary operator with 3 and 9 as its left and right operands, respectively. These are different from the modulus operators in C. Examples of binary operators are:- *(multiplication), %(modulus operator), ==(equality operator), &&(logical AND operator), &(Bitwise AND operator), etc.
  • Ternary operator: operates on three operands. The conditional operator(? 🙂 is the only ternary operator available in C.

Download Formulas for GATE Computer Science Engineering – Algorithms

Unary Operator in C Symbol

Check out the symbols of the various Unary Operator in C important for the GATE exam in the table provided below. These symbols are widely used in constructing a program. 

Unary Operator Symbol
Prefix Increment Operator ++a
Post Increment Operator a++
Unary plus +
Unary Minus
Prefix Decrement Operator –a
Post Decrement Operator a–

Types of Unary Operators in C

Having discussed the unary operator in C and various other types of operators based on the number of operands. Let us now see a few unary operators important as per the GATE question paper perspective, along with examples:

  • Prefix Increment Operator: It increments the value of the operator first and then stores it in the memory. In this, the operator is present on the left side of the operand. For instance int a=6; int b=++a; // b=7, a=7.
  • Post Increment Operator: It increments the value of the operator value after storing it in the memory. In this, the operator is present on the right side of the operand. For instance int a=6; int b=a++; // b=6, a=7.
  • Unary plus: It just signifies that a number is positive. The operand is an arithmetic type. Its result is the value of the operand. For example: int a= +8.
  • Unary minus: It just signifies that a number is negative. The operand is an arithmetic type. Its result is the value of the operand. For example: int a= -8.
  • Prefix Decrement Operator: It first decreases the operator’s value and stores it in the memory. In this, the operator is present on the left side of the operand. For instance int a=6; int b=–a; // b=5, a=5.
  • Post Decrement Operator: It decreases the operator’s value after storing it in the memory. In this, the operator is present on the right side of the operand. For instance int a=6; int b=a–; // b=6, a=5.

Important GATE Topics

FDD Full Form Resistors In Parallel
ISP Full Form Resistors In Series
Stress And Strain Properties Of Gases
IEEE Full Form Environmental Studies Mcqs
Two Port Network Fixed Beams
Our Apps Playstore
POPULAR EXAMS
SSC and Bank
Other Exams
GradeStack Learning Pvt. Ltd.Windsor IT Park, Tower - A, 2nd Floor, Sector 125, Noida, Uttar Pradesh 201303 help@byjusexamprep.com
Home Practice Test Series Premium