General and Web Programming Fundamentals
  • Introduction
  • Program creation and design
    • Program design
      • Algorithms
      • Pseudocode
    • Programming conventions
    • Writing programs
      • Source code editors
      • Integrated Development Environments
      • Code repositories/Version control
      • Compilers/Interpreters
  • Programming Fundamentals
    • Operators
      • Arithmetic
      • Logical
      • Assignment
    • Constants and Variables
    • Datatypes
      • Primitive Datatypes
        • Character
        • Integer
        • Boolean
        • Floating point
        • Nothing (Null)
      • Composite Datatypes
        • Arrays
        • Strings
        • Classes
        • Structs
      • Literals
    • Data structures
      • Lists
      • Queues
      • Stacks
      • Map/dictionary
      • Trees
      • Graphs
    • Control structures
      • Selection (Conditional)
        • If/Else
        • Ternary
        • Switch
      • Iteration (Loops)
        • For loops
        • While loops
        • Do-While loops
        • For-Each loops
    • Functions
      • Parameters and arguments
      • Lambda expressions
      • Higher Order Functions
    • Space and Time
    • Scope
    • Standard libraries
  • Programming Paradigms
    • Procedural (Imperative) Programming
    • Object-oriented programming
    • Functional Programming
    • Declarative Programming
    • Event Driven programming
  • Programming Languages
    • Short history of programming
    • Low-level programming languages
    • High-level programming languages
  • Web Development
    • What is the web?
      • Web browsers (clients)
      • Webservers (serving web pages)
      • W3C
    • Markup languages
      • HTML
        • HTML Tags
      • Cascading Style Sheets (CSS)
        • CSS Properties
      • XML
      • Markdown
    • Scripting Languages
      • JavaScript
      • TypeScript
    • JSON
    • JavaScript Frameworks
  • Acknowledgements
    • About the author(s)
  • License
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Programming Fundamentals

Operators

Operators in Computer Programming

Operators in computer programming are special symbols or keywords that are used to perform operations on operands (values or variables). These operations can range from basic arithmetic calculations to complex logical evaluations. Operators are fundamental to most programming languages, allowing the manipulation of data and the control of program flow.

Types of Operators:

  1. Arithmetic Operators:

    • Used for performing mathematical calculations.

    • Common operators include + (addition), - (subtraction), * (multiplication), / (division), and % (modulo operation, which gives the remainder of a division).

  2. Relational (Comparison) Operators:

    • Used for comparing two operands.

    • Include == (equal to), != (not equal to), > (greater than), < (less than), >= (greater than or equal to), and <= (less than or equal to).

  3. Logical Operators:

    • Used to perform logical operations, typically on boolean values.

    • Include && (logical AND), || (logical OR), and ! (logical NOT).

  4. Assignment Operators:

    • Used to assign values to variables.

    • The most basic assignment operator is =. There are also compound assignment operators like +=, -=, *= and /=, which combine arithmetic and assignment.

  5. Bitwise Operators:

    • Operate on individual bits of integer operands.

    • Include & (bitwise AND), | (bitwise OR), ^ (bitwise XOR), ~ (bitwise NOT), << (left shift), and >> (right shift).

  6. Unary Operators:

    • Operate on a single operand.

    • Examples include ++ (increment), -- (decrement), and - (negation).

  7. Ternary Operator (Conditional Operator):

    • A shorthand for the if-else statement.

    • In many languages, it's represented as ? :. For example, condition ? expression1 : expression2.

Characteristics of Operators:

  • Precedence: Operators have a defined precedence which determines the order in which they are evaluated in expressions. For example, multiplication and division have higher precedence than addition and subtraction.

  • Associativity: Defines the order in which operators of the same precedence are processed. For example, in left-to-right associativity, operators are evaluated from left to right.

Importance in Programming:

Operators are crucial in programming as they form the backbone of most computational and logical operations. Understanding how to use them effectively is key to writing efficient and readable code. Different programming languages might have variations in operators and their behaviors, but the fundamental concepts remain largely the same.

PreviousProgramming FundamentalsNextArithmetic

Last updated 1 year ago

Was this helpful?

Page cover image