Mastering Operators in C Programming

Welcome to the dynamic world of C programming! As you embark on your coding journey, understanding the fundamentals is key. In this introductory blog post, we'll unravel the essence of operators - the building blocks that empower you to manipulate data and craft powerful algorithms. Let's dive in!


Operators:

  • Operators are symbols in C that perform operations on one or more operands. They are the building blocks for executing tasks, ranging from arithmetic calculations to logical evaluations. Examples include addition “+”, subtraction “-“, and assignment “=”.

 

Operands:

  • Operands are the entities upon which operators act. These can be variables, constants, or expressions. In “a + b”, ”a”  and “b” are operands, and “+” is the operator.

 

Operator Precedence:

  • Operator precedence dictates the order in which operations are executed within an expression. Understanding this hierarchy is critical to avoiding ambiguity. For example, in “a + b * c”, multiplication takes precedence over addition, so “b * c” is evaluated first.

 

Associativity:

  • Associativity determines the direction in which operators of the same precedence are evaluated. It can be left-to-right or right-to-left. The assignment operator “=” is right-associative, meaning operations are performed from right to left in an expression like “a = b = c”.

Operators in C Programming Language

 

Arithmetic Operators:

 

  • + (Addition)
  • - (Subtraction)
  • * (Multiplication)
  • / (Division)
  • % (Modulus)

 

Relational Operators:

 

  • == (Equal to)
  • != (Not equal to)
  • < (Less than)
  • > (Greater than)
  • <= (Less than or equal to)
  • >= (Greater than or equal to)

 

Logical Operators:

 

  • && (Logical AND)
  • || (Logical OR)
  • ! (Logical NOT)

 

Bitwise Operators:

 

  • & (Bitwise AND)
  • | (Bitwise OR)
  • ^ (Bitwise XOR)
  • ~ (Bitwise NOT)
  • << (Left shift)
  • >> (Right shift)

 

Assignment Operators:

 

  • = (Assignment)
  • +=, -=, *=, /=, %= (Compound assignment)



Examples :-

Q1) Write a program to evaluate the polynomial shown here:

            3x^3 - 5x^2 + 6 for x = 2.55



Q2 ) Write a program that evaluates the following expression and displays the results: 
        (3.31 × 10-8 × 2.01 × 10-7) / (7.16 × 10-6 + 2.01 × 10-8) 



Team CodeCraze








Comments

Popular posts from this blog

Variables and Data Types in C

Type Casting, Command Line Arguments and Defining Constants.

How Computers Make Sense of Stuff: Data Processing Basics