Operators In C Programming Language - Passionate Geekz

Breaking

Where you can unleash your inner geek.

Tuesday, 2 April 2019

Operators In C Programming Language

You can perform various types of operations on those variables by having values ​​stored inside the variables. For example, by having value store inside two integer variables you can perform the operation of addition and print the sum of values ​​of those two variables. Similarly, you can do more with different operations variables. To perform operations with variables, you have to use different operators. In this Chapter, you are being told about the same operators. The variables that are used with operators in Operations are called operand. For example, see the statement given below.

c = a + b;

A and b is used with the operator (+) in the above statement, so these two variables are called operands. Operators are of 2 types. Unary – These types of operators are used only with one operand. Binary – 2 operands are used with this type of operators. Now let’s try to find out about different operators who are using C language.

Arithmetic Operators

Arithmetic operators are used to perform mathematical operations. Such as addition, subtraction, division and multiplication etc. Arithmetic operators are of 5 types. These are basic mathematical operators.

OperatorsDescription
+ (Addition)This operator adds values ​​of two variables.
– (Subtraction)This operator subtract the value of one variable from the value of one variable.
* (Multiplication)This operator Multiply the value of one variable from the value of one variable.
/ (Division)This operator Divide the value of one variable from the value of one variable.
% (Modulus)It is used to obtain the remaining value after the operator division.

Relational Operators

Relational operators are used to compare values ​​of two variables. As you can use these operators, you can find out if the values ​​of any two variables are equal and if not equal, which variable is the value of which variable and which variable is small? Such operators are used with conditional statements (if, if-else, switch, for, while etc). These operators are used to check the condition. If the condition is true, the value becomes true and the value becomes false when the condition is false. All the relational operators being used in the C language are given below.

Also Read:

[su_posts template=”templates/list-loop.php” posts_per_page=”5″ tax_term=”1834″ order=”desc”]

OperatorsDescriptions
== (Equal To)This operator checks whether the values ​​of both variables are equal.
!= (Not Equal To)This operator checks whether values ​​of both variables are non equal.
<  (Lesser Than)This operator checks whether the left operand is smaller than the value right operand.
> (Greater Than)This operator checks whether the left operand is larger than the value right operand.
<=  (Lesser than equal)This operator checks whether the left operand is equal to or equal to the value right operand.
>=  (Greater than equal)This operator checks whether the left operand is larger than or equal to the value right operand.

Logical Operators

Logical operators are used with decision making statements. These operators are used to control two statements together in control statements. For example, you can check 2 conditions instead of one in an if statement. The following about logical operators is being given.

OperatorsDescription
&& (AND)When both conditions are true then the control statement value becomes true.
|| (OR)When any one condition is true, the control statement value becomes true.
! (NOT)These operators are used with the same condition. When that condition is false then the control statement’s value becomes true.

Bitwise Operators

Bitwise operators are used to perform bit level operations on given variables. The decimal values ​​of the variables are converted to bits. After that the operations are performed on those bits. The bitwise operators used in the C language are being given below.

OperatorsDescription
& (Bitwise AND)This operator performs the AND operation with bits of the same position of both the variables.
| (Bitwise OR)This operator performs the OR operation with bits of the same position of both the variables.
~ (Bit wise NOT)These operators are used with just one operand. All the bits of the value of that variable are reversed with the variable with which it is used. As if 0 is 1 then it becomes 1 and then 1 becomes zero.
^ (XOR)This is a special type of OR operator. This operator returns 1 when the opposite is bits and returns 0 to the same bit.
<< (Left Shift)This operator left side of the variable’s bits shift in the left side of the variable in the right side as shift.
>> (Right Shift)The operator left side variables of the variables shift in the right side of the variable in the right.

As you know, work with bitwise operators bits. Let’s say you have created 2 variables a and b in the program. In these two variables, you have stored 3 and 5 values ​​respectively. To work on their bits, you can convert them to binary first .3 = 000000115 = 00000101 They have been converted into binary only with the purpose of explaining to you. You do not need to insert binary values ​​into the program. Store computer information only in binary form. All the operations defined above will be performed on these bits only.

Assignment Operators

Assignment operators are used to assign values ​​of variables to each other. Below are some of the different assignment operators used in C language.

OperatorsDescription
=This operator assigns the value of the operand of the right side to the operand of the left side.
+=This operator assigns the value of the operand of right side in the operand left side and assigns the operand with the result left side. You can also write it in this way. a = a + b;
-=This operator subtract the value of the operand of the right side operand from the value of operand left side and store it in the result left side variable. You can also write it in this way. a = a-b;
*=This operator stores the left side of the operand with the value of the operand value of the right side and stores the result in the operand of the left side.
/=It divides the value of operator left operand with the value of right operand and stores the result in the operand of the left side.
%=This operator divides the value of the operand left side with the value of the operand of the right side and stores the remaining result in the operand of the left side.

Increment/Decrements operators

You can use increment / decrements operators to increase or decrease the value of any variable instantly by a number. These are being given below.

 OperatorsDescription
 ++ (increment)This is a unary operator. It increases the value of the operand by a number. When it seems before the operand, the value is increment first and is used later. When this operator operates after operand, the increment after the value of the operand is used.
 –(decrements)This is also a unary operator. This decreases the value of the operand by one number. When it is used before the operand, the value decreases before the value is used. When it is used after the variable, the value is first used and later decreases.

Conditional (?:) Operator

Conditional operator is also called ternary operator. This is a short form of if-else statement. Its general structure is like this.

contion ? stmnt1 : stmnt 2;

If condition is true then the statement will return one or the statement will return 2. An example of this is being given below.

5>3 ? true : false;

Special C Operators

OperatorsDescription
sizeof (var_name )This operator returns the size of the variables in memory.
&This returns the memory address of operator variables.
*This operator returns the pointer of the variable.

No comments:

Post a Comment