Operators in C-1 | Programming and Data Structures - Computer Science Engineering (CSE) PDF Download

What is a C Operator?

An operator in C can be defined as the symbol that helps us to perform some specific mathematical, relational, bitwise, conditional, or logical computations on values and variables. The values and variables used with operators are called operands. So we can say that the operators are the symbols that perform operations on operands.

Operators in C-1 | Programming and Data Structures - Computer Science Engineering (CSE)

Types of Operators in C

C language provides a wide range of operators that can be classified into 6 types based on their functionality:

  1. Arithmetic Operators
  2. Relational Operators
  3. Logical Operators
  4. Bitwise Operators
  5. Assignment Operators

1.Arithmetic Operators

Operators in COperators in C

Operators are the foundation of any programming language. Thus the functionality of C language is incomplete without the use of operators. Operators allow us to perform different kinds of operations on operands. In C, operators in Can be categorized in following categories: 

  • Arithmetic Operators (+, -, *, /, %, post-increment, pre-increment, post-decrement, pre-decrement)
  • Relational Operators (==, !=, >, <, >= & <=) Logical Operators (&&, || and !)
  • Bitwise Operators (&, |, ^, ~, >> and <<)
  • Assignment Operators (=, +=, -=, *=, etc)
  • Other Operators (conditional, comma, sizeof, address, redirection)

Arithmetic Operators: These are used to perform arithmetic/mathematical operations on operands. The binary operators falling in this category are:

  • Addition: The ‘+’ operator adds two operands. For example, x + y.
  • Subtraction: The ‘-‘ operator subtracts two operands. For example, x - y.
  • Multiplication: The ‘*’ operator multiplies two operands. For example, x * y.
  • Division: The ‘/’ operator divides the first operand by the second. For example, x / y.
  • Modulus: The ‘%’ operator returns the remainder when first operand is divided by the second. For example, x%y.

C
// C program to demonstrate
// working of binary arithmetic
// operators
#include <stdio.h>
int main()
{
    int a = 10, b = 4, res;
    // printing a and b
    printf("a is %d and b is %d\n", a, b);
    res = a + b; // addition
    printf("a+b is %d\n", res);
    res = a - b; // subtraction
    printf("a-b is %d\n", res);
    res = a * b; // multiplication
    printf("a*b is %d\n", res);
    res = a / b; // division
    printf("a/b is %d\n", res);
    res = a % b; // modulus
    printf("a%%b is %d\n", res);
    return 0;
}

C++
#include <iostream>
using namespace std;
int main() {
    int a = 10, b = 4, res;
    // printing a and b
    cout<<"a is "<<a<<" and b is "<<b<<"\n";
    // addition
    res = a + b;
    cout << "a+b is: "<< res << "\n";
    // subtraction
    res = a - b;
    cout << "a-b is: "<< res << "\n";
    // multiplication
    res = a * b;
    cout << "a*b is: "<< res << "\n";
    // division
    res = a / b;
    cout << "a/b is: "<< res << "\n";
  // modulus
   res = a % b;
    cout << "a%b is: "<< res << "\n";
    return 0;
}

Output:
a is 10 and b is: 4
a + b is: 14
a - b is: 6
a * b is: 40
a / b is: 2
a % b is: 2

The ones falling into the category of unary arithmetic operators are:

  • Increment: The ‘++’ operator is used to increment the value of an integer. When placed before the variable name (also called pre-increment operator), its value is incremented instantly. For example, ++x.
    And when it is placed after the variable name (also called post-increment operator), its value is preserved temporarily until the execution of this statement and it gets updated before the execution of the next statement. For example, x++.
  • Decrement: The ‘ – – ‘ operator is used to decrement the value of an integer. When placed before the variable name (also called pre-decrement operator), its value is decremented instantly. For example, – – x.
    And when it is placed after the variable name (also called post-decrement operator), its value is preserved temporarily until the execution of this statement and it gets updated before the execution of the next statement. For example, x – –.

C
// C program to demonstrate working of Unary arithmetic operators
#include <stdio.h>
int main()
{
    int a = 10, b = 4, res;
    // post-increment example:
    // res is assigned 10 only, a is not updated yet
    res = a++;
    printf("a is %d and res is %d\n", a,
           res); // a becomes 11 now
    // post-decrement example:
    // res is assigned 11 only, a is not updated yet
    res = a--;
    printf("a is %d and res is %d\n", a,
          res); // a becomes 10 now
    // pre-increment example:
    // res is assigned 11 now since
    // a is updated here itself
    res = ++a;
    // a and res have same values = 11
    printf("a is %d and res is %d\n", a, res);
    // pre-decrement example:
    // res is assigned 10 only since a is updated here
    // itself
    res = --a;
    // a and res have same values = 10
   printf("a is %d and res is %d\n", a, res);
    return 0;
}

C++
#include <iostream>
using namespace std;
int main()
{
    int a = 10, b = 4, res;
    // post-increment example:
    // res is assigned 10 only,
    // a is not updated yet
    res = a++;
    // a becomes 11 now
    cout << "a is " << a
         << " and res is "
         << res << "\n";
    // post-decrement example:
    // res is assigned 11 only,
    // a is not updated yet
    res = a--;
    // a becomes 10 now
   cout << "a is " << a
         << " and res is "
         << res << "\n";
    // pre-increment example:
    // res is assigned 11 now
    // since a is updated here itself
    res = ++a;
    // a and res have same values = 11
    cout << "a is " << a
       << " and res is "
        << res << "\n";
    // pre-decrement example:
    // res is assigned 10 only
    // since a is updated here
    // itself
    res = --a;
    // a and res have same values = 10
    cout << "a is " << a
         << " and res is "
         << res << "\n";
    return 0;
}

Output:
a is 11 and res is 10
a is 10 and res is 11
a is 11 and res is 11
a is 10 and res is 10

2.Relational Operators

Relational OperatorsRelational Operators

Relational operators are used for comparison of two values to understand the type of relationship a pair of number shares. For example, less than, greater than, equal to etc. Let’s see them one by one

  1. Equal to operator: Represented as ‘==’, the equal to operator checks whether the two given operands are equal or not. If so, it returns true. Otherwise it returns false. For example, 5==5 will return true.
  2. Not equal to operator: Represented as ‘!=’, the not equal to operator checks whether the two given operands are equal or not. If not, it returns true. Otherwise it returns false. It is the exact boolean complement of the ‘==’ operator. For example, 5!=5 will return false.
  3. Greater than operator: Represented as ‘>’, the greater than operator checks whether the first operand is greater than the second operand or not. If so, it returns true. Otherwise it returns false. For example, 6>5 will return true.
  4. Less than operator: Represented as ‘<‘, the less than operator checks whether the first operand is lesser than the second operand. If so, it returns true. Otherwise it returns false. For example, 6<5 will return false.
  5. Greater than or equal to operator: Represented as ‘>=’, the greater than or equal to operator checks whether the first operand is greater than or equal to the second operand. If so, it returns true else it returns false. For example, 5>=5 will return true. 
  6. Less than or equal to operator: Represented as ‘<=’, the less than or equal tooperator checks whether the first operand is less than or equal to the second operand. If so, it returns true else false. For example, 5<=5 will also return true.

Examples:
C
// C program to demonstrate working of relational operators #include <stdio.h>
int main()
{
      int a = 10, b = 4;
      // greater than example
      if (a > b)
         printf("a is greater than b\n");
      else
         printf("a is less than or equal to b\n");
     // greater than equal to
     if (a >= b)
        printf("a is greater than or equal to b\n");
     else
       printf("a is lesser than b\n");
     // less than example
     if (a < b)
         printf("a is less than b\n");
      else
        printf("a is greater than or equal to b\n");
     // lesser than equal to
     if (a <= b)
        printf("a is lesser than or equal to b\n");
       else
        printf("a is greater than b\n");
      // equal to if (a == b)
        printf("a is equal to b\n");
       else
        printf("a and b are not equal\n");
       // not equal to
       if (a != b)
         printf("a is not equal to b\n");
         else
         printf("a is equal b\n"); return 0; }
C++
// C++ program to demonstrate working of logical operators
#include <iostream>
using namespace std;
int main()
{
     int a = 10, b = 4;
     // greater than example
     if (a > b)
         cout << "a is greater than b\n";
     else
        cout << "a is less than or equal to b\n";
     // greater than equal to
      if (a >= b)
       cout << "a is greater than or equal to b\n";
    else
      cout << "a is lesser than b\n";
      // less than example if (a < b)
      cout << "a is less than b\n";
    else
      cout << "a is greater than or equal to b\n";
     // lesser than equal to
       if (a <= b)
     cout << "a is lesser than or equal to b\n";
   else
      cout << "a is greater than b\n";
     // equal to if (a == b) cout << "a is equal to b\n";
   else
     cout << "a and b are not equal\n";
     // not equal to if (a != b)
     cout << "a is not equal to b\n";
    else
     cout << "a is equal b\n";
          return 0;
}
Output:

  • a is greater than b
  • a is greater than or equal to b
  • a is greater than or equal to b
  • a is greater than b
  • a and b are not equal a is not equal to b

3. Logical Operators

They are used to combine two or more conditions/constraints or to complement the evaluation of the original condition under consideration. They are described below:

  1. Logical AND operator: The ‘&&’ operator returns true when both the conditions under consideration are satisfied. Otherwise it returns false. For example, a && b returns true when both a and b are true (i.e. non-zero).
  2. Logical OR operator: The ‘||’ operator returns true even if one (or both) of the conditions under consideration is satisfied. Otherwise it returns false. For example, a || b returns true if one of a or b or both are true (i.e. non-zero). Of course, it returns true when both a and b are true.
  3. Logical NOT operator: The ‘!’ operator returns true the condition in consideration is not satisfied. Otherwise it returns false. For example, !a returns true if a is false, i.e. when a = 0.

Examples:
C
// C program to demonstrate working of logical operators
#include <stdio.h>
int main()
{
      int a = 10, b = 4, c = 10, d = 20;
      // logical operators
      // logical AND example
      if (a > b && c == d)
           printf("a is greater than b AND c is equal to d\n");
      else
           printf("AND condition not satisfied\n");
      // logical AND example
      if (a > b || c == d)
           printf("a is greater than b OR c is equal to d\n");
     else
           printf("Neither a is greater than b nor c is equal " " to d\n");
     // logical NOT example
     if (!a)
         printf("a is zero\n");
     else
         printf("a is not zero");
     return 0;
}

C++
// C++ program to demonstrate working of
// logical operators
#include <iostream>
using namespace std;
int main()
{
      int a = 10, b = 4, c = 10, d = 20;
      // logical operators
     // logical AND example
     if (a > b && c == d)
         cout << "a is greater than b AND c is equal to d\n";
   else
        cout << "AND condition not satisfied\n";
      // logical AND example
      if (a > b || c == d)
     cout << "a is greater than b OR c is equal to d\n";
    else
       cout << "Neither a is greater than b nor c is equal "
     " to d\n";
     // logical NOT example
       if (!a)
     cout << "a is zero\n";
   else
     cout << "a is not zero";
   return 0;
}
Output:
AND condition not satisfied
a is greater than b OR c is equal to d
a is not zero

Short-Circuiting in Logical Operators

1. In case of logical AND, the second operand is not evaluated if first operand is false. For example, program 1 below doesn’t print “EdurevQuiz” as the first operand of logical AND itself is false.
C
#include <stdbool.h>
#include <stdio.h>
int main()
{
       int a = 10, b = 4;
      bool res = ((a == b) && printf("EdurevQuiz"));
      return 0;
}

C++
#include <iostream>
using namespace std;
int main()
{
     int a = 10, b = 4;
bool res = ((a == b) && cout << "EdurevQuiz");
return 0;
}
Output: No Output

But below program prints “EdurevQuiz” as first operand of logical AND is true:
C
#include <stdbool.h>
#include <stdio.h>
int main()
{
     int a = 10, b = 4;
     bool res = ((a != b) && printf("EdurevQuiz"));
     return 0;
}

C++
#include <iostream>
using namespace std;
int main()
{
     int a = 10, b = 4;
    bool res = ((a != b) && cout << "EdurevQuiz");
return 0;
}

Output: EdurevQuiz

2. In case of logical OR, the second operand is not evaluated if first operand is true. For example, program 1 below doesn’t print “EdurevQuiz” as the first operand of logical OR itself is true.
C
#include <stdbool.h>
#include <stdio.h>
int main()
{
     int a = 10, b = 4;
     bool res = ((a != b) || printf("EdurevQuiz"));
     return 0;
}

C++
#include <stdbool.h>
#include <stdio.h>
int main()
{
       int a = 10, b = 4;
      bool res = ((a != b) || cout << "EdurevQuiz");
      return 0;
}
Output: No Output

But below program prints “EdurevQuiz” as first operand of logical OR is false:
C
#include <stdbool.h>
#include <stdio.h> int main()
{
      int a = 10, b = 4;
      bool res = ((a == b) ||
      printf("EdurevQuiz"));
      return 0;
}

C++
#include <stdbool.h>
#include <stdio.h>
int main()
{
      int a = 10, b = 4;
      bool res = ((a == b) || cout << "EdurevQuiz");
      return 0;
}
Output: EdurevQuiz

4. Bitwise Operators

In C, the following 6 operators are bitwise operators (work at bit-level)
Operators in C-1 | Programming and Data Structures - Computer Science Engineering (CSE)

  1. The & (bitwise AND) in C or C++ takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1.
  2. The | (bitwise OR) in C or C++ takes two numbers as operands and does OR on every bit of two numbers. The result of OR is 1 if any of the two bits is 1.
  3. The ^ (bitwise XOR) in C or C++ takes two numbers as operands and does XOR on every bit of two numbers. The result of XOR is 1 if the two bits are different.
  4. The << (left shift) in C or C++ takes two numbers, left shifts the bits of the first operand, the second operand decides the number of places to shift.
  5. The >> (right shift) in C or C++ takes two numbers, right shifts the bits of the first operand, the second operand decides the number of places to shift.
  6. The ~ (bitwise NOT) in C or C++ takes one number and inverts all bits of it

Example:
// C Program to demonstrate use of bitwise operators
#include <stdio.h>
int main()
{
    // a = 5(00000101), b = 9(000010001)
    unsigned char a = 5, b = 9;
    // The result is 00000001
    printf("a = %d, b = %d\n", a, b);
    printf("a&b = %d\n", a & b);
    // The result is 00001101
    printf("a|b = %d\n", a | b);
    // The result is 00001100
    printf("a^b = %d\n", a ^ b);

    // The result is 11111010
    printf("~a = %d\n", a = ~a);
    // The result is 00010010
    printf("b<<1 = %d\n", b << 1);
    // The result is 00000100
    printf("b>>1 = %d\n", b >> 1);
    return 0;
}

Output:
a = 5, b = 9
a&b = 1
a|b = 13
a^b = 12
~a = 250
b<<1 = 18
b>>1 = 4

Interesting facts about bitwise operators:

1. The left shift and right shift operators should not be used for negative numbers: If any of the operands is a negative number, it results in undefined behaviour. For example results of both -1 << 1 and 1 << -1 is undefined. Also, if the number is shifted more than the size of integer, the behaviour is undefined. For example, 1 << 33 is undefined if integers are stored using 32 bits. See this for more details.
2. The bitwise XOR operator is the most useful operator from technical interview perspective: It is used in many problems. A simple example could be “Given a set of numbers where all elements occur even number of times except one number, find the odd occurring number” This problem can be efficiently solved by just doing XOR of all numbers.
#include <stdio.h>
// Function to return the only odd
// occurring element
int findOdd(int arr[], int n)
{
    int res = 0, i;
    for (i = 0; i < n; i++)
        res ^= arr[i];
    return res;
}
// Driver Method
int main(void)
{
    int arr[] = { 12, 12, 14, 90, 14, 14, 14 };
    int n = sizeof(arr) / sizeof(arr[0]);
    printf("The odd occurring element is %d ",
           findOdd(arr, n));
    return 0;
}
Output: The odd occurring element is 90

The following are many other interesting problems using XOR operator:

  • Find the Missing Number
  • swap two numbers without using a temporary variable
  • A Memory Efficient Doubly Linked List
  • Find the two non-repeating elements.
  • Find the two numbers with odd occurences in an unsorted-array.
  • Add two numbers without using arithmetic operators.
  • Swap bits in a given number/.
  • Count number of bits to be flipped to convert a to b .
  • Find the element that appears once.
  • Detect if two integers have opposite signs.

3. The bitwise operators should not be used in place of logical operators. The result of logical operators (&&, || and !) is either 0 or 1, but bitwise operators return an integer value. Also, the logical operators consider any non-zero operand as 1. For example, consider the following program, the results of & and && are different for same operands.
#include <stdio.h>
int main()
{
    int x = 2, y = 5;
    (x & y) ? printf("True ") : printf("False ");
    (x && y) ? printf("True ") : printf("False ");
    return 0;
}
Output: False True
4. The left-shift and right-shift operators are equivalent to multiplication and division by 2 respectively: As mentioned in point 1, it works only if numbers are positive.
#include <stdio.h>
int main()
{
    int x = 19;
    printf("x << 1 = %d\n", x << 1);
    printf("x >> 1 = %d\n", x >> 1);
    return 0;
}
Output:
x << 1 = 38
x >> 1 = 9
5. The & operator can be used to quickly check if a number is odd or even: The value of expression (x & 1) would be non-zero only if x is odd, otherwise the value would be zero.
#include <stdio.h>
int main()
{
    int x = 19;
    (x & 1) ? printf("Odd") : printf("Even");
    return 0;
}
Output: Odd
6. The ~ operator should be used carefully: The result of ~ operator on a small number can be a big number if the result is stored in an unsigned variable. And the result may be a negative number if the result is stored in a signed variable (assuming that the negative numbers are stored in 2’s complement form where the leftmost bit is the sign bit)
// Note that the output of the following
// program is compiler dependent
#include <stdio.h>
int main()
{
    unsigned int x = 1;
    printf("Signed Result %d \n", ~x);
    printf("Unsigned Result %ud \n", ~x);
    return 0;
}
Output:
Signed Result -2
Unsigned Result 4294967294d

Operator Precedence and Associativity in C

Operator precedence determines which operator is performed first in an expression with more than one operators with different precedence.
For example: Solve
10 + 20 * 30
Operator PrecedenceOperator Precedence10 + 20 * 30 is calculated as 10 + (20 * 30)
and not as (10 + 20) * 30
Operators Associativity is used when two operators of same precedence appear in an expression. Associativity can be either Left to Right or Right to Left.
For example: ‘*’ and ‘/’ have same precedence and their associativity is Left to Right, so the expression “100 / 10 * 10” is treated as “(100 / 10) * 10”.
Operator AssociativityOperator Associativity

Operators Precedence and Associativity are two characteristics of operators that determine the evaluation order of sub-expressions in absence of brackets

For example: Solve
100 + 200 / 10 - 3 * 10

Operators Precedence and AssociativityOperators Precedence and Associativity1. Associativity is only used when there are two or more operators of same precedence: The point to note is associativity doesn’t define the order in which operands of a single operator are evaluated. For example, consider the following program, associativity of the + operator is left to right, but it doesn’t mean f1() is always called before f2(). The output of the following program is in-fact compiler dependent.
// Associativity is not used in the below program.
// Output is compiler dependent.
#include <stdio.h>
int x = 0;
int f1()
{
    x = 5;
    return x;
}
int f2()
{
    x = 10;
    return x;
}
int main()
{
    int p = f1() + f2();
    printf("%d ", x);
    return 0;
}
2. All operators with the same precedence have same associativity

This is necessary, otherwise, there won’t be any way for the compiler to decide evaluation order of expressions which have two operators of same precedence and different associativity. For example + and – have the same associativity.
3. Precedence and associativity of postfix ++ and prefix ++ are different
Precedence of postfix ++ is more than prefix ++, their associativity is also different. Associativity of postfix ++ is left to right and associativity of prefix ++ is right to left. See this for examples.
4. Comma has the least precedence among all operators and should be used carefully For example consider the following program, the output is 1.
#include <stdio.h>
int main()
{
    int a;
    a = 1, 2, 3; // Evaluated as (a = 1), 2, 3
   printf("%d", a);
    return 0;
}
5. There is no chaining of comparison operators in C

In Python, expression like “c > b > a” is treated as “c > b and b > a”, but this type of chaining doesn’t happen in C. For example consider the  following program. The output of following program is “FALSE”.
#include <stdio.h>
int main()
{
    int a = 10, b = 20, c = 30;
    // (c > b > a) is treated as ((c  > b) > a), associativity of '>'
    // is left to right. Therefore the value becomes ((30 > 20) > 10)
    // which becomes (1 > 20)
    if (c > b > a)
        printf("TRUE");
    else
        printf("FALSE");
    return 0;
}
Please see the following precedence and associativity table for reference.

Operators in C-1 | Programming and Data Structures - Computer Science Engineering (CSE)
Operators in C-1 | Programming and Data Structures - Computer Science Engineering (CSE)
Operators in C-1 | Programming and Data Structures - Computer Science Engineering (CSE)
Operators in C-1 | Programming and Data Structures - Computer Science Engineering (CSE)
It is good to know precedence and associativity rules, but the best thing is to use brackets, especially for less commonly used operators (operators other than +, -, *.. etc). Brackets increase the readability of the code as the reader doesn’t have to see the table to find out the order.

Evaluation order of operands

Consider the below program:

C++
// C++ implementation
#include <bits/stdc++.h>
using namespace std;
int x = 0;
int f1()
{
    x = 5;
    return x;
}
int f2()
{
    x = 10;
    return x;
}
int main()
{
    int p = f1() + f2();

    cout << ("%d ", x);
    getchar();
    return 0;
}

C
#include <stdio.h>
int x = 0;
int f1()
{
    x = 5;
    return x;
}
int f2()
{
    x = 10;
    return x;
}
int main()
{
    int p = f1() + f2();
    printf("%d ", x);
    getchar();
    return 0;
}

Java
class GFG {

    static int x = 0;

    static int f1()

    {

        x = 5;

        return x;

    }

    static int f2()

    {

        x = 10;

        return x;

    }

    public static void main(String[] args)

    {

        int p = f1() + f2();

        System.out.printf("%d ", x);

    }

}

// This code is contributed by Rajput-Ji

Python3

# Python3 implementation of the above approach
class A():
    x = 0;
    def f1():
        A.x = 5;
        return A.x;
    def f2():
        A.x = 10;
        return A.x;
# Driver Code
p = A.f1() + A.f2();
print(A.x);
# This code is contributed by mits

C#
// C# implementation of the above approach
using System;
class GFG {
    static int x = 0;
    static int f1()
    {
        x = 5;
        return x;
    }
    static int f2()
    {
        x = 10;
        return x;
    }

    // Driver code
    public static void Main(String[] args)
    {
        int p = f1() + f2();
        Console.WriteLine("{0} ", x);
    }
}
// This code has been contributed

// by 29AjayKumar

PHP
<?php
// PHP implementation of the above approach
$x = 0;
function f1()
{
    global $x;
    $x = 5;
    return $x;
}
function f2()
{
    global $x;
    $x = 10;
    return $x;
}
// Driver Code
$p = f1() + f2();
print($x);
// This code is contributed by mits
?>

Javascript
<script>
x = 0;
function f1()
{
    x = 5;
    return x;
}
function f2()
{
    x = 10;
    return x;
}
var p = f1() + f2();
document.write(x);
    // This code is contributed by Amit Katiyar
</script>

Output:  10

What would the output of the above program – ‘5’ or ’10’? 
The output is undefined as the order of evaluation of f1() + f2() is not mandated by standard. The compiler is free to first call either f1() or f2(). Only when equal level precedence operators appear in an expression, the associativity comes into picture. For example, f1() + f2() + f3() will be considered as (f1() + f2()) + f3(). But among first pair, which function (the operand) evaluated first is not defined by the standard. 

The document Operators in C-1 | Programming and Data Structures - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Programming and Data Structures.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
119 docs|30 tests

Top Courses for Computer Science Engineering (CSE)

FAQs on Operators in C-1 - Programming and Data Structures - Computer Science Engineering (CSE)

1. What are the arithmetic operators in C/C++?
Ans. Arithmetic operators in C/C++ include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).
2. What are the relational and logical operators in C/C++?
Ans. Relational operators in C/C++ include equal to (==), not equal to (!=), greater than (>), less than (<), greater than or equal to (>=), and less than or equal to (<=). Logical operators include AND (&&), OR (||), and NOT (!).
3. What are bitwise operators in C/C++ used for?
Ans. Bitwise operators in C/C++ are used for manipulating individual bits of integers. They include bitwise AND (&), bitwise OR (|), bitwise XOR (^), bitwise NOT (~), left shift (<<), and right shift (>>).
4. How are arithmetic operators different from relational operators in C/C++?
Ans. Arithmetic operators perform mathematical operations like addition and subtraction, while relational operators compare values and return a boolean result (true or false).
5. Can logical operators be used with arithmetic operators in C/C++?
Ans. Yes, logical operators can be used with arithmetic operators in C/C++. This allows for more complex conditions to be evaluated in conditional statements.
119 docs|30 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

past year papers

,

Previous Year Questions with Solutions

,

Summary

,

practice quizzes

,

Operators in C-1 | Programming and Data Structures - Computer Science Engineering (CSE)

,

pdf

,

mock tests for examination

,

shortcuts and tricks

,

Extra Questions

,

Operators in C-1 | Programming and Data Structures - Computer Science Engineering (CSE)

,

ppt

,

Sample Paper

,

Semester Notes

,

Important questions

,

Viva Questions

,

study material

,

Objective type Questions

,

Exam

,

Free

,

MCQs

,

video lectures

,

Operators in C-1 | Programming and Data Structures - Computer Science Engineering (CSE)

;