# C – Operator and Expression8 min read

Operators are the mathematical symbols that are used to perform a mathematical operation on operands. These symbols tell the compiler to perform respective operations. An expression is formed by joining constants and variables in C programming.

Example:

In the above example, 10 and 5 are operands and + is the operation performed between these two operands.

Types of Operator in C:

• Arithmetic Operator
• Increment and Decrement Operators
• Relational Operator
• Assignment Operators
• Logical Operators
• Bitwise Operators
• sizeof Operator
• Other Operators

## C Arithmetic Operator

These are used to perform mathematical operations on operands such as addition, subtraction, multiplication, division etc.

• Subtraction: ‘-‘ operator subtracts two operands. eg, a-b.
• Multiplication: ‘*’ operator multiplies two operands. eg, a*b.
• Division: ’/’ operator divides the operand by the second. eg, a/b.
• Modulus: ’%’ operator returns the remainder when the first operand is divided by the second. For example, a%b.

#### Example of Arithmetic Operator

The output of Arithmetic Operator:

## C Increment and Decrement Operators

These are the Unary Operators as they operate on a single operand. They are `++` and `--` operators. ++ is used to increase the value by 1 and — is used to decrease the value by 1. There are two kinds of Increment and Decrement Operators.

• Post-Increment or Post-Decrement:
First, the value is used for operation and then incremented or decremented. Represented as a++ or a–.
• Pre-Increment Pre-Decrement:
Here First the value is incremented or decremented then used for the operation. Represented as ++a or –a.

#### Example of Increment and Decrement Operator

The output of Increment and Decrement Operator.

## C Relational Operator

Relational operators are used to compare two values and return boolean results. These operators are used to check for relations like equality, greater than, less than between two values. They are used with a loop statement and also with if-else statements.

#### Example of Relational Operator

The output of Relational Operator.

## C Assignment Operators

Assignment operator is used to assigning a value to any variable. This operator assigns the value of the right-hand side of an operator to the left-hand side.
These are the short version formed by combining the two operators.

For example Instead of writing, `int a = a+3`, we can write `a += 3`.

• Assignment operator: ‘=’ This operator assigns the value on the right to the variable on the left.
`a = 20; B = 30; Ch = 'cha';`
• Add AND assignment operator: ‘+=’ This operator first adds the current value of the variable on the left to the value on the right and then assigns the result to the variable on the left.
`c+=7; a+=b;`
• Subtract AND assignment operator: ‘-=’ This operator first subtracts the current value of the variable on the left from the value on the right and then assigns the result to the variable on the left.
`c-=7; a-=b;`
• Multiply AND assignment operator: ‘*=’ This operator first multiplies the current value of the variable on the left to the value on the right and then assigns the result to the variable on the left.
`c*=7; a*=b;`
• Divide AND assignment operator: ‘/=’ This operator first divides the current value of the variable on the left by the value on the right and then assigns the result to the variable on the left.
`c/=7; a/=b;`
• Modulus AND assignment operator: ‘%=’ It takes modulus using two operands and assigns the result to the left operand.
`C %= A is equivalent to C = C % A ;`

#### Example ofAssignment Operators

The output of Assignment Operators:

## CLogical Operators

Logical Operators are used in conditional statements and loops for evaluating a condition with binary values. All of the binary logical operators return two boolean values that are true and false depending upon 0 and 1.

#### Example ofLogical Operators

The output of Logical Operator.

## C Bitwise Operators

In C programming, Bitwise operators are used to perform a bit-level operation. All the mathematical operations are converted to bit-level which makes processing faster and also saves power.

#### Example of Bitwise Operators.

The output of Bitwise operator.

## sizeof Operator

`sizeof `operator is a unary operator that returns the size of constants, variables, array, etc.
Example: sizeof(x), return size of the variable x.

#### Example of sizeof Operator

The output of sizeof Operator.

## Other Operators:

### C Program to demonstrate & and * operator

In this C program, & is used to get the address of a variable and * is used to get the value of variable.

Output: `10`

### Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …

### String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …

### Java Program to Find pair of Integers in Array whose sum is given Number

In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …

### Program to Print Diamond Alphabet Patterns in C

In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …

### Half Diamond Pattern in C using Alphabets

In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …

### Half Pyramid of Alphabets in C

In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …