C Operators, Precedence & 6 Real-World Practice Programs

โšก C (C17 / C23 Standard) ๐ŸŸข Lesson 5 ๐Ÿ“‚ Phase 03: Input & Operators ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this in-depth guide: Arithmetic & Modulus ยท Relational & Logical ยท Prefix vs Postfix (++x/x++) ยท Bitwise ยท Ternary ยท Precedence Table ยท 6 Practice Programs

Welcome to Phase 3 (Part 2): C Operators, Expression Evaluation & 6 Practice Programs Masterclass! Operators are the fundamental building blocks that allow you to perform computations, make logical decisions, and manipulate raw binary bits in memory. In this comprehensive guide, you will master all C operator categories (Arithmetic, Relational, Logical, Bitwise, Ternary), prefix vs postfix increment/decrement mechanics, operator precedence & associativity rules, and construct 6 real-world practical computation programs.

1Complete C Operators Classification

C language provides 6 major families of operators:

1. Arithmetic Operators
  • + (Addition), - (Subtraction)
  • * (Multiplication), / (Division)
  • % (Modulus / Remainder) โš ๏ธ Integers only!
2. Relational (Comparison)
  • == (Equal to), != (Not equal)
  • >, <, >=, <=
  • Returns 1 for True, 0 for False
3. Logical Operators
  • && (Logical AND โ€” Short-circuit!)
  • || (Logical OR โ€” Short-circuit!)
  • ! (Logical NOT / Inversion)
4. Bitwise Operators
  • & (Bitwise AND), | (Bitwise OR)
  • ^ (XOR), ~ (NOT / Invert bits)
  • << (Left Shift), >> (Right Shift)
2Prefix vs Postfix (++x / x++) & Ternary Operator

โšก Prefix (++x) vs Postfix (x++) Mechanics

โ€ข Prefix (++x): Value ni First increment chesi, tharvatha current expression lo use chesthundhi ("Increment first, use later").
โ€ข Postfix (x++): Current expression lo Original value ni use chesi, tharvatha increment chesthundhi ("Use first, increment later").

Conditional (Ternary) Operator: condition ? expr1 : expr2

Simple if-else conditions ni single-line expression ga rayadaniki vadathamu:
int max = (a > b) ? a : b;

3Operator Precedence & Associativity Master Table โญ

Complex expressions lo eeh operator mundhu evaluate avvali anedhi Precedence decide chesthundhi:

PriorityOperatorsDescriptionAssociativity
1 (Highest)(), [], ->, .Parentheses, Array Subscript, Member AccessLeft to Right
2++, --, !, ~, +, -, (type), *, &, sizeofUnary operators, Type cast, Address, DereferenceRight to Left
3*, /, %Multiplication, Division, ModulusLeft to Right
4+, -Addition, SubtractionLeft to Right
5<<, >>Bitwise Left and Right ShiftsLeft to Right
6<, <=, >, >=Relational ComparisonsLeft to Right
7==, !=Equality / InequalityLeft to Right
8&Bitwise ANDLeft to Right
9^Bitwise XORLeft to Right
10|Bitwise ORLeft to Right
11&&Logical ANDLeft to Right
12||Logical ORLeft to Right
13?:Ternary ConditionalRight to Left
14 (Lowest)=, +=, -=, *=, /=, %=Assignment & Compound AssignmentsRight to Left
46 Real-World Practice Programs (Formulas & Walkthroughs)

Practical implementation of arithmetic and operator logic across 6 essential algorithms:

๐Ÿ“Œ Formulas Used in the 6 Programs:

1. Add Two Numbers: $Sum = a + b$
2. Simple Interest: $SI = rac{P imes T imes R}{100}$
3. Rectangle Area & Perimeter: $Area = L imes W$, $Perimeter = 2(L + W)$
4. Celsius to Fahrenheit: $F = (C imes rac{9.0}{5.0}) + 32.0$
5. Student Average: $Avg = rac{M_1 + M_2 + M_3}{3.0}$
6. Bill Calculator: $Final = Subtotal + (Subtotal imes rac{GST%}{100})$

C โ€” All 6 Practice Programs in One Comprehensive Suite โ–ถ Run Programs
#include <stdio.h>

int main(void) {
    // 1. Add Two Numbers
    int num1 = 45, num2 = 30;
    printf("1. Sum of %d + %d = %d\n", num1, num2, num1 + num2);

    // 2. Simple Interest: P = 10000, T = 2 years, R = 7.5%
    double P = 10000.0, T = 2.0, R = 7.5;
    double SI = (P * T * R) / 100.0;
    printf("2. Simple Interest on Rs.%.0f: Rs.%.2f\n", P, SI);

    // 3. Rectangle Area & Perimeter (L = 12.5, W = 6.0)
    double length = 12.5, width = 6.0;
    double area = length * width;
    double perimeter = 2.0 * (length + width);
    printf("3. Rectangle Area = %.2f sq.units | Perimeter = %.2f units\n", area, perimeter);

    // 4. Celsius to Fahrenheit (37ยฐC normal body temp)
    double celsius = 37.0;
    double fahrenheit = (celsius * 9.0 / 5.0) + 32.0;
    printf("4. 37ยฐC in Fahrenheit = %.1fยฐF\n", fahrenheit);

    // 5. Student Average Marks (85, 92, 78)
    int m1 = 85, m2 = 92, m3 = 78;
    double average = (m1 + m2 + m3) / 3.0; // Using 3.0 avoids integer division!
    printf("5. Student Average: %.2f%%\n", average);

    // 6. Supermarket Bill Calculator with 18% GST
    double itemPrice = 1250.0;
    int quantity = 3;
    double subtotal = itemPrice * quantity;
    double finalBill = subtotal + (subtotal * 0.18);
    printf("6. Bill: Subtotal = Rs.%.2f | With 18%% GST = Rs.%.2f\n", subtotal, finalBill);

    return 0;
}
๐Ÿ’ป Try It Yourself โ€” Run Arithmetic Suite in Live C Compiler

Test arithmetic operations, Celsius conversion, and student average in our live GCC compiler:

C (GCC Standard) โ–ถ Open C Compiler
#include <stdio.h>

int main(void) {
    double celsius = 100.0; // Boiling point of water
    double fahrenheit = (celsius * 9.0 / 5.0) + 32.0;

    printf("%.1fยฐC = %.1fยฐF\n", celsius, fahrenheit);
    return 0;
}
Open in Online C Compiler โ†’