⏱️ 6min read
Difficulty level: Easy
160K+ career-aspirant learners have read this article 👨🏻💻 on C Operators!
C operators are one of the features in C which has symbols that can be used to perform mathematical, relational, bitwise, conditional, or logical manipulations. The C programming language has a lot of built-in operators to perform various tasks as per the need of the program. Usually, operators take part in a program for manipulating data and variables and form a part of the mathematical, conditional, or logical expressions.
🕵🏻♂️ Did You Know?
Some of the most-asked interview questions for C Programming roles are:
- What is the difference between an array and a pointer in C?
- How do I declare an array in C?
- How do I access array elements in C?
Have a great start to finding the answers & strengthening your C programming skills by availing this free course on ‘C Basics Online Tutorial Course for Beginners’ with a SkillUp verified certificate 📃upon completion.
In other words, we can also say that an operator is a symbol that tells the compiler to perform specific mathematical, conditional, or logical functions. It is a symbol that operates on a value or a variable. For example, + and - are the operators to perform addition and subtraction in any C program. C has many operators that almost perform all types of operations. These operators are really useful and can be used to perform every operation.
Additionally, you can also learn more about the uses of C language.
Types of Operators in C
- Arithmetic Operator
- Increment/Decrement Operator
- Assignment Operator
- Logical Operator
- Bitwise Operator
- Misc Operator
Let's look at these operators in c in detail.
Arithmetic Operator With Example
Arithmetic Operators are the operators which are used to perform mathematical calculations like addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). It performs all the operations on numerical values (constants and variables).
The following table provided below shows all the arithmetic operators supported by the C language for performing arithmetic operators.
It adds two operands
It subtracts second operand from the first
It multiplies both operands
It is responsible for dividing numerator by the denomerator
This operator gives the remainder of an integer after division
Enroll in this free course on C Basics now, unlock the verified certificate & become job-ready for Programmer/ Developer roles!
Let’s look at an example of arithmetic operations in C below assuming variable a holds 7 and variable b holds 5.
// Examples of arithmetic operators in C
int a = 7,b = 5, c;
c = a+b;
printf("a+b = %d \n",c);
c = a-b;
printf("a-b = %d \n",c);
c = a*b;
printf("a*b = %d \n",c);
c = a/b;
printf("a/b = %d \n",c);
c = a%b;
printf("Remainder when a is divided by b = %d \n",c);
a+b = 12
a-b = 2
a*b = 35
a/b = 1
Remainder when a divided by b = 2
The operators shown in the program are +, -, and * that computes addition, subtraction, and multiplication respectively. In normal calculation, 7/5 = 1.4. However, the output is 1 in the above program. The reason behind this is that both the variables a and b are integers. Hence, the output should also be an integer. So, the compiler neglects the term after the decimal point and shows 2 instead of 2.25 as the output of the program.
Showcase a verified certificate of completion on your resumé to advance your Programming/ Developer career by 2X faster with salary hike