Saturday, June 30, 2018

C programming operators


What is operator in C programming language?

Operator in C is a symbol. It will tell compiler to perform either mathematical or logical functions. Moreover, in C programming language there are many C operator programs. You will find here complete list of C operators in C with examples.

List of C arithmetic operators

Name of the operatorDescription
+It will add two operands
/Divides numerator by the de-numerator
*Operator will multiply both operands
It will subtract second operand from first operand
++This operator is increment operator. It will increase integer value by one
%This is a modulus operator. And remainder of after integer division
It is decrement operator. It decreases integer value by one
Program examples

Logical operators list in C programming language

Operator’s nameDescription
||This is Logical OR Operator. When any two operands is non-zero. Then condition becomes true
!It is Logical NOT Operator. You can use it to reverse logical state of operand. In addition, when condition is true, then Logical NOT operator makes it false
&&Finally, this is Logical AND operator. In case, both operands are non-zero. Then condition will become true
Example programs

Relational operators in C language

Operator’s nameDescription
!=It checks values of two operands are equal or not. When values are not equal. Then condition becomes true
==Checks values of two operands are equal or not. When yes, then condition will become true
<Checks value of left operand is less than value of right operand. And if yes. Then condition will be true
>Checks value of left operand is greater than value of right operand. In case yes, then condition will be true
>=This operator will check value of left operand is greater than or equal to value of right operand. Moreover, if yes, then condition changes to true
<=It will check value of left operand is less than or equal to value of right operand. Furthermore, if yes, then condition will be true
Example programs


List of C language bitwise operators

Name of the operatorDescription
|This is Binary OR Operator. It copies bit if it is there in either operand
&Binary AND Operator will copy bit to result if there in both operands
<<It is Binary Left Shift Operator. Here, left operands value moves left by
number of bits. Moreover, right operand specifies bits
>>Binary Right Shift Operator. Here, left operands value moves right by number of bits. Again right operand will specify bits
^Binary XOR Operator will copy bit when it is set in one operand only
~Finally, this is Binary Ones Complement Operator. It is unary. Additionally, it has effect of flipping bits
Example programs

List of Misc Operators – sizeof & ternary operators in C

Operator’s nameDescription
? :It is conditional expression
sizeof()It will return size of variable
*It will point to variable
&& returns address of variable
Program examples

Assignment operators of C language

OperatorDescription of the operator
=Simple assignment operator will assign values from right side operand to left side operand
-=This is Subtract AND assignment operator. It will subtract right operand from left operand. Moreover, it assigns result to left operand.
+=Add AND assignment operator. It will add right operand to left operand. Moreover, assigning result to left operand is its responsibility
%=This is Modulus AND assignment operator. In addition, it will take modulus using two operands. In addition, it assigns result to left operand
*=Multiply AND assignment operator multiplies right operand with left operand. It will also assign result to left operand
/=Divide AND assignment operator divides left operand with right operand. In addition, it will assign result to left operand
&=It is Bitwise AND assignment operator
<<=This operator is Left shift AND assignment
>>=It is Right shift AND assignment operator
|=Bitwise inclusive OR and assignment operator
^=Finally, this operator is Bitwise exclusive OR and assignment
Example programs

C operators precedence and associativity

An operator precedence will decide grouping of terms in expressions. It will also decide how to evaluate expressions. However, you must remember that few C operators will have more precedence than the others.
You can check below list. Because here you will know C operators precedence and associativity. In addition, table has highest precedence operator first. In addition, the list will go from higher to lower precedence. You may even look at C operators associativity.

List of C operators precedence and associativity in C programming language

Name of the categoryAssociativityOperator
PostfixLeft to right() [] -> . ++ – –
UnaryRight to left+ – ! ~ ++ – – (type)* & sizeof
MultiplicativeLeft to right* / %
AdditiveLeft to right+ –
ShiftLeft to right<< >>
RelationalLeft to right< <= > >=
EqualityLeft to right== !=
Bitwise ANDLeft to right&
Bitwise XORLeft to right^
Bitwise ORLeft to right|
Logical ANDLeft to right&&
Logical ORLeft to right||
ConditionalRight to left?:
AssignmentRight to left= += -= *= /= %=>>= <<= &= ^= |=
CommaLeft to right,
Program examples





So now you know C operators programs examples. Practise C operators in C and C operators precedence. This will help you with C functions chapter.










No comments:

Post a Comment