Table of Contents
ToggleOperator in C programmingÂ
In C programming, an operator is a symbol that tells the compiler to perform a specific mathematical, relational, or logical operation on one or more values (called operands). An operand is a value or variable on which an operator acts. In simple words:
Example:Â a+b ; + is the operator and a and b are operands
Types of operators on the Basic Number of Operands
According to the number of operands required for an operator, the operators are classified into unary, binary,a nd ternary operators
- Unary Operator: Unary operators operate on a single operand to perform actions like increment, decrement, negation, etc. They are commonly used for changing the value or evaluating a condition.
Examples include
++a,--a,-a, and!a Binary Operators (in C): Binary operators work with two operands and perform operations such as arithmetic, comparison, or assignment. They are the most commonly used operators in C programming. Examples include
a + b,a > b, anda = b.Ternary Operator (in C): The ternary operator works with three operands and is used as a shorthand for a
if-elsestatement. Its syntax is:condition ? value_if_true : value_if_false;Example:int max = (a > b) ? a : b;Â
Types of operators on the Basic Utility or functions
1. Arithmetic operators
In C programming, arithmetic operators are used to perform basic mathematical calculations on numeric data types. The primary arithmetic operators include addition (+), subtraction (-), multiplication (*), and division (/), along with the modulus operator (%) for obtaining the remainder of the division.
2. Relational Operator:
In C programming, relational operators are used to compare two values or expressions, returning a boolean result (true or false). The primary relational operators include equal to (==), not equal to (!=), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to (<=). These operators are essential for making decisions and controlling the flow of a program through conditional statements.
| Operator | Description | Example |
|---|---|---|
| == | Equal to | a == b |
| != | Not equal to | a != b |
| > | Greater than | a > b |
| < | Less than | a < b |
| >= | Greater than or equal to | a >= b |
| <= | Less than or equal to | a <= b |
3 Logic operators:
In C programming, logical operators are used to perform logical operations on boolean values, returning true or false based on the evaluation of the expressions. The primary logical operators include AND (&&), OR (||), and NOT (!). These operators are essential for constructing complex conditional statements and controlling the flow of a program.

Â
4. Assignment Operators :
In C programming, an assignment operator is used to assign a value to a variable. The most common assignment operator is=, which sets the variable on the left to the value on the right. For example, int a = 5; assigns the value 5 to the variable a.
5. Increment and Decrement Operators:Â
In C programming, increment and decrement operators are used to increase or decrease the value of a variable by 1. The increment operator is ++ and the decrement operator is --.
- They can be used in prefix form (e.g.,
++a) or postfix form (e.g.,a++). Prefix changes the value before use, while postfix uses the value before changing it.
6. Conditional Operator
In C programming, the conditional operator (also called the ternary operator) is a concise way to perform conditional evaluations. It is the only ternary operator in C, taking three operands, and is often used as a shorthand for simple if-else statements.
Example
#include <stdio.h> int main() { int a = 10, b = 5; int max; // Using conditional operator to find the maximum max = (a > b) ? a : b; printf("Maximum value is: %d\n", max); // Output: Maximum value is: 10 return 0; }
Special OperatorsÂ
C language includes several special operators that perform unique operations beyond basic arithmetic and logic. Here are the most important special operators:
Special Operators in C:
- Comma OperatorÂ
( , ) sizeof Operator- Address-of OperatorÂ
( & ) - Pointer Dereference OperatorÂ
( * ) - Ternary (Conditional) OperatorÂ
( ? : ) - Bitwise Operators:
- Bitwise ANDÂ
( & ) - Bitwise ORÂ
( | ) - Bitwise XORÂ
( ^ ) - Bitwise NOTÂ
( ~ ) - Left ShiftÂ
( << ) - Right ShiftÂ
( >> )
Write a program to read two numbers from the user and determine the larger number using the conditional operator
#include <stdio.h>
int main() {
int num1, num2, larger; // Variable declaration
printf("Enter first number: "); // Prompt for first number
scanf("%d", &num1); // Read first number
printf("Enter second number: "); // Prompt for second number
scanf("%d", &num2); // Read second number
larger = (num1 > num2) ? num1 : num2; // Find larger using ternary operator
printf("The larger number is: %d\n", larger);// Display result
return 0; // Exit program
}
