Computer Programming – Basic Operators

Basic Operators

In every programming language, operators are the symbols used to perform operations on values and variables. Think of operators as tools that help your program calculate results, compare values, or make decisions. Just like arithmetic in real life uses +, –, ×, and ÷, programming languages provide their own sets of operators.

Different languages (C, Java, Python) may have slight variations, but the fundamental concepts remain the same. This chapter introduces the most common operator categories you will use in your programs.


What Are Operators?

Operators tell the computer what action to perform. They work on values called operands.
Example:

10 + 20

Here:

  • 10 and 20 → operands
  • + → operator

Types of Operators

Most programming languages support the following categories of operators:


Arithmetic Operators

These operators perform basic mathematical operations.

OperatorMeaningExample
+Additiona + b
Subtractiona – b
*Multiplicationa * b
/Divisiona / b
%Modulusa % b (remainder)

Assignment Operators

Assignment operators are used to assign values to variables.

OperatorMeaningExample
=Assign valuex = 10
+=Add and assignx += 5 (x = x + 5)
-=Subtract and assignx -= 3
*=Multiply and assignx *= 2
/=Divide and assignx /= 2

Relational (Comparison) Operators

These operators compare two values and return true or false.

OperatorMeaningExample
==Equal toa == b
!=Not equal toa != b
>Greater thana > b
<Less thana < b
>=Greater or equala >= b
<=Less or equala <= b
basic operators, programming operators, arithmetic operators, relational operators, logical operators, assignment operators, C operators, Java operators, Python operators, programming tutorial

Logical Operators

Logical operators help combine conditions.

OperatorMeaningExample
&& (and) / andTrue if both conditions are truea > 5 && b < 10
|| (or) / orTrue if at least one condition is truea == 10 || b == 20
! (not)Reverses condition!false → true

Unary Operators

These operate on a single operand.

OperatorMeaningExample
++Incrementx++
Decrementx–
Unary minus-x

Example in C

#include <stdio.h>

int main() {
    int a = 10, b = 20;
    int result = a + b;

    printf("Result = %d", result);
    return 0;
}

Example in Java

class Main {
    public static void main(String[] args) {
        int a = 10, b = 20;
        int result = a + b;

        System.out.println("Result = " + result);
    }
}

Example in Python

a = 10
b = 20
result = a + b

print("Result =", result)

When Do You Use Operators?

You will use operators when you need to:

  • Perform calculations
  • Compare values
  • Make decisions using conditions
  • Work with loops
  • Update variable values

Operators are used in almost every line of code you write.

FAQ

What are basic operators in programming?

Basic operators are symbols used to perform operations such as addition, comparison, or logical evaluation in a program.

Are operators the same in all programming languages?

Most languages share similar operator concepts, but syntax differences may exist.

What is the difference between = and ==?

= assigns a value, while == compares two values.

What does the modulus operator (%) do?

It returns the remainder of a division operation.

Why are operators important in programming?

They allow programs to perform calculations, make decisions, and control the flow of execution.

Related Article
Computer Programming Tutorial for Beginners – Learn Coding Step by Step (C, Python, Java)

Computer Programming Tutorial for Beginners – Learn Coding Step by Step Computer programming is the process of writing a series Read more

Computer Programming Overview

Computer Programming Overview Computer programming begins with understanding what a computer program is and how it operates. A computer program Read more

Computer Programming Basics

Computer Programming – Basics Understanding computer programming begins with learning the foundational building blocks that every programming language is built Read more

Computer Programming Environment

Computer Programming – Environment Before writing your first computer program, you must prepare the correct programming environment. Although the environment Read more

Computer Programming – Basic Syntax

Before diving into advanced programming concepts, it’s important to understand how basic syntax works in different Computer Programming languages. Syntax Read more

Computer Programming – Data Types

Data types are one of the most important concepts in programming. A data type defines the kind of data a Read more

Computer Programming Variables

In any programming language, a variable is one of the most fundamental concepts. A variable acts as a named storage Read more

Computer Programming – Keywords

In earlier chapters, you learned two essential programming concepts: variables and data types. You also saw how different data types Read more

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments