C
  • Introduction
    • Fundamentals of a Program
    • Overview of C
    • Features of C
  • Installing Required Software
    • Setting Up VSCode for Windows
    • Setting Up VSCode for macOS
    • Setting Up VSCode for Ubuntu
  • Starting to write code
    • Compiling and Running Your Code
    • Creating Our First C Program
    • Errors and Warnings
    • Program: Writing a C Program to Display Your Name
    • Structure of a C Program
  • Basic Concepts
    • Comments in C
    • Preprocessor in C
    • The #include Statement
    • Displaying Output
    • Reading Input from the Terminal
    • Enums and Chars
    • Data Types and Variables
    • Format Specifiers
    • Command Line Arguments
    • Program: Calculating the Area of a Triangle
  • Operators
    • Converting Minutes to Years and Days
    • Basic Operators
    • Bitwise Operators
    • Program: Byte Sizes of Basic Data Types
    • cast and sizeof Operators
    • Operator Precedence
  • Control Flow
    • If-Else Statements
    • Program: Weekly Pay Calculation
    • Switch Statement
    • For Loop
    • While and Do-While Loops
    • Nested Loops and Loop Control
    • Program: Guess the Number
  • Arrays
    • Introduction to Arrays
    • Program: Prime Number Generator
    • Multidimensional Arrays
    • Program: simple Weather Program
    • Variable Length Arrays (VLAs)
  • Functions
    • Overview of Functions
    • Defining Functions
    • Arguments and Parameters
    • Returning Data from Functions
    • Variable Scoping
    • Program: Tic Tac Toe Game
    • Recursion
  • Strings
    • Defining a String
    • Constant Strings in C
    • Common String Functions
    • Program: Bubble Sort
    • Searching, Tokenizing, and Analyzing Strings
    • Converting Strings
  • Debugging
    • What is Debugging
    • Understanding the Call Stack
    • Common C Mistakes
    • Understanding Compiler Errors
  • Pointer
    • Defining Pointers
    • Accessing Pointers
    • Program: Pointer Demonstration
    • Pointers and Const
    • Void Pointers
    • String Pointers
    • Array Pointers
    • Utilizing Pointers with Functions
    • Pointer Arithmetic
  • Dynamic Memory Allocation
    • malloc, calloc, and realloc
    • Program: User Input String
    • Memory Deallocation
  • Structure
    • Structures and Arrays
    • Nested Structures
    • Structures and Pointers
    • Structures and Functions
    • Program: Structure pointers and Functions
  • File Input and Output
    • Accessing Files
    • Reading from a File
    • Program: Finding the Total Number of Lines in a Text File
    • Writing to a Text File
    • Finding Your Position in a File
    • Program: Converting Characters in a File to Uppercase
    • Program: Printing the Contents of a File in Reverse Order
  • The Standard C Library
    • Various Functions in C
    • Math Functions in C
    • Utility Functions in C
Powered by GitBook
On this page
  • 1. Arithmetic Operators
  • 2. Assignment Operator
  • 3. Comparison Operators
  • 4. Logical Operators
  • Conclusion

Was this helpful?

  1. Operators

Basic Operators

Operators in C are symbols that perform operations on variables and values. Here is an overview of basic operators in C:

1. Arithmetic Operators

Arithmetic operators perform mathematical operations on numerical values.

  • Addition (+): Adds two operands.

    int result = 5 + 3;  // Result is 8
  • Subtraction (-): Subtracts the right operand from the left operand.

    int result = 10 - 4;  // Result is 6
  • Multiplication (*): Multiplies two operands.

    int result = 3 * 7;  // Result is 21
  • Division (/): Divides the left operand by the right operand.

    float result = 15.0 / 2.0;  // Result is 7.5
  • Modulus (%): Returns the remainder when the left operand is divided by the right operand.

    int result = 10 % 3;  // Result is 1

2. Assignment Operator

The assignment operator (=) is used to assign a value to a variable.

int num = 42;  // Assigns the value 42 to the variable 'num'

3. Comparison Operators

Comparison operators compare two values and return a Boolean result (true or false).

  • Equal to (==): Checks if two values are equal.

    int a = 5, b = 5;
    if (a == b) {
        // Code executed if 'a' is equal to 'b'
    }
  • Not equal to (!=): Checks if two values are not equal.

    int x = 10, y = 20;
    if (x != y) {
        // Code executed if 'x' is not equal to 'y'
    }
  • Greater than (>): Checks if the left operand is greater than the right operand.

  • Less than (<): Checks if the left operand is less than the right operand.

  • Greater than or equal to (>=): Checks if the left operand is greater than or equal to the right operand.

  • Less than or equal to (<=): Checks if the left operand is less than or equal to the right operand.

4. Logical Operators

Logical operators perform logical operations and return a Boolean result.

  • Logical AND (&&): Returns true if both operands are true.

  • Logical OR (||): Returns true if at least one operand is true.

  • Logical NOT (!): Returns true if the operand is false, and vice versa.

int age = 25;
if (age >= 18 && age <= 30) {
    // Code executed if age is between 18 and 30
}

Conclusion

These basic operators in C provide the foundation for performing various operations in your programs. As you progress, you'll encounter more operators and gain a deeper understanding of their usage.

In the upcoming sections, we'll explore more advanced topics in C programming. If you have specific questions or areas you'd like to delve into further, feel free to ask. Happy coding!

PreviousConverting Minutes to Years and DaysNextBitwise Operators

Was this helpful?