What is Operators in C Language?

The C language supports a wide set of built-in operators. An operator is a symbol that tells the compiler to perform a particular mathematical or logical operation. Operators are used programmatically to manipulate data and variables. Operators are symbols that help to perform operations of a mathematical and logical nature.

Types of Operators:

1. Arithmetic Operators:

These operators are arithmetic or mathematical operations such as addition (+), subtraction (-), multiplication (*), division (/), remainder of division (%), increment (++), decrement (-). ..

Types of Arithmetic Operators:

  • Unary Operators: This type of operator works with a single value (operand) such as ++ or -.
  • Binary Operators: this type of operator works with two operands, such as +, -, *, /.

This is a picture of the number of C arithmetic operators and the functions they perform.

For example:
Here code:
#include <stdio.h>
int main()
{
	int a = 12, b = 6, 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 divided by b = %d \n", c);
	return 0;
}

2. Relational Operators:

Relational operators are used when comparing the values ​​of two operands. Use the> = operator to ensure that one operand is greater than or equal to the other.

The following image is a list of C relational operators and their functions.

For example:
Here Code:
#include <stdio.h>
int main()
{
int a = 7, b = 7, c = 10;
printf("%d == %d = %d \n", a, b, a == b); // true
printf("%d == %d = %d \n", a, c, a == c); // false
printf("%d > %d = %d \n", a, b, a > b); //false
printf("%d > %d = %d \n", a, c, a > c); //false
printf("%d < %d = %d \n", a, b, a < b); //false
printf("%d < %d = %d \n", a, c, a < c); //true
printf("%d != %d = %d \n", a, b, a != b); //false
printf("%d != %d = %d \n", a, c, a != c); //true
printf("%d >= %d = %d \n", a, b, a >= b); //true
printf("%d >= %d = %d \n", a, c, a >= c); //false
printf("%d <= %d = %d \n", a, b, a <= b); //true
printf("%d <= %d = %d \n", a, c, a <= c); //true
return 0;
}

3. Logical operators:

Logical operators are used for true or false results.

The following image shows the logical operators used in C.

For example:
Here Code:
#include <stdio.h>
int main()
{
int a = 8, b = 8, c = 12, result;
result = (a == b) && (c > b);
printf("(a == b) && (c > b) equals to %d \n", result);
result = (a == b) && (c < b);
printf("(a == b) && (c < b) equals to %d \n", result);
result = (a == b) || (c < b);
printf("(a == b) || (c < b) equals to %d \n", result);
result = (a != b) || (c < b);
printf("(a != b) || (c < b) equals to %d \n", result);
result = !(a != b);
printf("!(a == b) equals to %d \n", result);
result = !(a == b);
printf("!(a == b) equals to %d \n", result);
return 0;
}

4. Bitwise Operators:

These operators are used for bit-level operations on operands. The operator is first converted to the bit level and then the calculation is performed.

For example:
Here Code:
#include <stdio.h>
int main()
{
	int a = 10, b = 8;
	printf("Output = %d", a&b);
	return 0;
}

5. Assignment Operators:

These types of operators are used to assign values ​​to variables.

6. Conditional Operators:

Also, the ternary operator or? :operator. These are used for decision making.

Syntax: Expression 1? Expression 2: Expression 3

7. Special Operators:

Some special operators used in C are:

For example:
Here Code:
#include <stdio.h>
int main()
{
	int *ptr, q;
	q = 40;
/* address of q is assigned to ptr */
	ptr = &q;
/* display q's value using ptr variable */
	printf("%d", *ptr);
	return 0;
}

Conclusion:

Operators are the basic foundation of the C / C ++ programming language. You can now use other conditions to perform any mathematical, logical, or relational operation.

References:

Help Me Please: If you found any error in the content or example please let us know by comment also write your suggestion or if any doubt in the concept please feel free to write us in the comment section.

Practice your Code online here

(Visited 60 times, 1 visits today)

0 0 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
You cannot copy content of this page
Scroll Up
0
Would love your thoughts, please comment.x
()
x

  • Name

  • Minimum length of 8 characters.