6 Basic Types of Operators In C

Arithmetic Operators In C

Here are C’s five basic arithmetic operators:

  • The + operator adds its operands. For example, 4 + 20 evaluates to 24.
  • The – operator subtracts the second operand from the first. For example, 12 – 3 evaluates to 9.
  • The * operator multiplies its operands. For example, 28 * 4 evaluates to 112.
  • The / operator divides its first operand by the second. For example, 1000 / 5 evaluates to 200. If both operands are integers, the result is the integer portion of the quotient. For example, 17 / 3 is 5, with the fractional part discarded.
  • The %operator finds the modulus of its first operand with respect to the second. That is, it produces the remainder of dividing the first by the second. For example, 19 % 6 is 1 because 6 goes into 19 three times, with a remainder of 1. Both operands must be integer types; using the % operator with floating-point values causes a compile-time error. If one of the operands is negative, the sign of the result depends on the implementation.

Of course, you can use variables as well as constants for operands. Listing 3.10 does just that. Because the % operator works only with integers, we’ll leave it for a later example.

This table shows us the major function and use of arithmetic operators

Arithmetic Operator in Java
Arithmetic Operator in Java

Let’s take an example that shows us the perfect use of arithmetic operators and makes us more clear.


void main() 

// we will add these two numbers 
  int n = 25;
  int m = 13;
  printf("Total of n + m = ", (n + m));


Output on Screen:
Total of n + m = 38;

See also  Quick Guide on Internal Structure of C Language in Just 5 Minutes

Increment and decrement operators

Increment operators are used for increasing the value of the variable by one and decrement operators are used to decrease the value of the variable by one.

Both increment and decrement operators are used on a single operand or variable, so it is called a unary operator. Unary operators are having a higher priority than the other operators it means unary operators are executed before other operators.
Example program;


void main()
int x,i;
printf("x: %d",x);
printf("i: %d",i);

Output on Screen:

X: 11

I: 11

Comments in C

Comments are notes of explanation that document lines or sections of a program.
Single-Line Comments – This can be done by using “//” this symbol at the start of the line.
// This is a single-line comment
Multiple Line Comments – This can be done by using “/*” this symbol at the starting point and ends with “*/” this symbol at the endpoint.

This is multiple

Programming Style in C

Programming style refers to the way a programmer uses identifiers, spaces, tabs, blank lines, and punctuation characters to visually arrange a program’s source code.

Best programming styles to use in a program to make more readable and good-looking with a professional approach.

  • Readability
  • Maintainability
  • Comments
  • Naming

Further visit: Recursion In C: All-inclusive Just In 5 Minutes

Decision Making Programming in c

Relational Operators

Relational operators allow you to compare numerically and char values and determine whether one is greater than, Jess than, equal to, or not equal to another.

The table below shows the exact detail of relational operators

Relational Operators in C
Relational Operators in C

So, we already understand from the table above that now it’s time to understand through the example of this understanding, here below is the example with the solution.

See also  Functions in C: Complete Guide in Just 5 Minutes
Expressions in C
Expressions in C

Logical Operators

Logical operators connect two or more relational expressions into one or reverse the logic of an expression.

Logical Operators in C
Logical Operators in C

The above table, I created is just to show you what is the purpose of these operators in c program with if/else/if/else if statement
Note: This program shows us about OR operator and AND operator with if statement.

Share and Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *