Operators in C Language – BKNMU Junagadh | BCA Sem 1 Notes



BCA Sem 1  |  Unit 1  |  Computer Concepts & C Programming

Operators in C Language — BKNMU Junagadh

Arithmetic, Relational, Logical, Bitwise, Assignment, Increment/Decrement & Special Operators

BKNMU Junagadh NEP 2020 C Operators Precedence & Associativity Expression Evaluation
In simple words: An Operator is a symbol that instructs the C compiler to perform specific mathematical, logical, or relational manipulations on data. The values or variables on which operators act are called Operands (for example, in a + b, + is the operator, while a and b are operands).
📖 Classification Based on Number of Operands

C operators can be categorized into three groups based on how many operands they operate upon:

++a, -x, !flag

1. Unary Operators

Operates on a single operand. Examples: Increment (++), Decrement (--), Logical NOT (!), Address-of (&).

a + b, x == y

2. Binary Operators

Operates on two operands. Includes Arithmetic (+, -, *, /, %), Relational, and Logical operators.

(a > b) ? a : b

3. Ternary Operator

Operates on three operands. C has exactly one ternary operator: Conditional Operator (?:).

🎨 Major Categories of Operators in C

The 8 Major Operator Types

1. Arithmetic (+, -, *, /, %) 2. Relational (<, >, ==, !=) 3. Logical (&&, ||, !)
4. Assignment (=, +=, -=) 5. Increment / Decrement (++, --) 6. Bitwise (&, |, ^, <<, >>)
1️⃣ Comprehensive Table of C Operators

Here is a detailed breakdown of all 8 functional operator categories in C:

CategoryOperatorsDescriptionExample Expression
Arithmetic+, -, *, /, %Performs basic mathematical calculations (Note: % gives remainder)10 % 31
Relational<, >, <=, >=, ==, !=Compares two values; returns 1 (True) or 0 (False)5 > 31
Logical&& (AND), || (OR), ! (NOT)Combines conditional expressions(x > 0 && y < 10)
Assignment=, +=, -=, *=, /=, %=Assigns right-hand value to left-hand variablex += 5 (same as x = x + 5)
Increment / Decrement++, --Increases or decreases variable value by 1 (Prefix & Postfix)a++ or ++a
Bitwise&, |, ^, ~, <<, >>Performs bit-level operations on binary bits5 & 3 (Bitwise AND)
Conditional? :Shorthand for if-else condition evaluationmax = (a > b) ? a : b;
Specialsizeof, &, *, ,Returns memory size, address, pointer dereference, or separates expressionssizeof(int)2/4 Bytes
ℹ️ Modulo Operator (%) Rule: The modulo operator % calculates the remainder of integer division. It can ONLY be used with integer operands (e.g., 5.5 % 2 is a compile error!).
🔍 Pre-Increment (++x) vs Post-Increment (x++)
Pre-Increment (++x)
  • Rule: "Change first, then use."
  • Increments value of x by 1 first
  • Uses updated value in current expression
  • Example: If x=5, y = ++x;x=6, y=6
Post-Increment (x++)
  • Rule: "Use first, then change."
  • Uses current value of x in expression first
  • Increments x by 1 afterwards
  • Example: If x=5, y = x++;x=6, y=5
💻 Code Sample — Operators in Action

Observe how different operators evaluate expressions in a working C program:

#include <stdio.h> int main() { int a = 10, b = 3; // 1. Arithmetic & Modulo printf("Division: %d, Remainder: %d\n", a / b, a % b); // 2. Relational & Logical if (a > b && b > 0) { printf("Both conditions are True!\n"); } // 3. Ternary Operator int max = (a > b) ? a : b; printf("Maximum value: %d\n", max); return 0; }
💡 Exam Tip: Operator Precedence determines which operator is evaluated first in a complex expression (e.g., * before +). Operator Associativity determines direction (Left-to-Right or Right-to-Left) when operators have equal precedence!
🔄 Operator Precedence Hierarchy (Top to Bottom)
1

Highest Priority: Brackets & Unary

(), [], Unary ++, --, !, sizeof (Associativity: Right-to-Left for Unary).

2

Arithmetic Priority

Multiplicative *, /, % evaluated before Additive +, - (Associativity: Left-to-Right).

3

Relational & Logical Priority

Relational <, > evaluated before Logical && and ||.

4

Lowest Priority: Assignment & Comma

Assignment operators (=, +=) and comma , are evaluated last (Associativity: Right-to-Left for Assignment).

⚠️ Common Exam Pitfall: Never confuse Assignment Operator = (assigns value) with Equal To Relational Operator == (compares equality)! Writing if (x = 5) will assign 5 to x and evaluate as True!
📝 Quick Revision — Key Exam Points
  • Operator & Operand: Operator specifies action; Operand is data being operated on.
  • 3 Classifications: Unary (1 operand), Binary (2 operands), Ternary (3 operands).
  • Modulo Operator (%): Returns remainder of integer division; invalid for floating-point values.
  • Logical Operators: && (AND - both true), || (OR - at least one true), ! (NOT - flips result).
  • Ternary Operator: condition ? expr1 : expr2; — shorthand for if-else.
  • Short-Circuit Evaluation: In &&, if first condition is false, second condition is not evaluated.
  • sizeof Operator: Returns size of data type/variable in bytes.

Post a Comment

Thanks for comment.

Previous Post Next Post