Operators

Operators are used to performing operations on variables and values.

In C language, There are the following types of operators:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators
  • Bitwise operators

Arithmetic Operators

Arithmetic Operators are used to doing mathematical calculations.

OperatorNameMeaningExample
+AdditionAdds 2 valuesx+y
SubtractionSubstracts one value from another valuex-y
*MultiplicationMultiplies two valuesx*y
/DivisionDivides one value by another valuex/y
%ModulusReturns the remainder of the divisionx%y
++IncrementIncreases the value of a variable by 1x++
DecrementDecreases the value of a variable by 1x–

Assignment Operators

Assignment Operators are used to assigning the value to a variable.

OperatorExampleSame asMeaning
=x=2x=2Assigning 2 to x variable
+=x += 2x = x+2Adding 2 to x variable’s value and assigning value to x
-=x -= 2x = x-2Subtracting 2 to x variable’s value and assigning value to x
*=x *= 2x = x*2Multiplying 2 to x variable’s value and assigning value to x
/=x /= 2x = x/2Dividing 2 to x variable’s value and assigning value to x
%=x %= 2x = x%2Assigning division remainder to variable x
&=x &= 2x = x&2
|=x |= 2x = x | 2
^=x ^= 2x = x^2
>>=x >>= 2x = x >> 2
<<=x <<= 2x = x << 2

Comparison Operators

Comparison operators are used to comparing two values and return true or false. Its the comparison is right then it will be true otherwise false.

OperatorNameExample
==is equal toa==b
!=is not equal toa!=b
>is greater thana>b
<is less thana<b
>=is greater than and equal toa>=b
<=is less than and equal toa<=b

Logical Operators

Logical operators are used to checking if it is true or false.

OperatorNameMeaningExample
&&Logical andIt returns true if both statements are true otherwise returns false.a > 2 && b < 3
||Logical orIt returns true if either 1st statement or 2nd statement is true, otherwise returns false.a > 2 || b < 3
!Logical notIt reverses the false to true and true to false.!(a > 2 || b < 3)

Size of Operator

The sizeof operator returns the size of a variable in bytes.

Example:

int myInt = 1;
printf("%d", sizeof(myInt));

Bitwise Operators

OperatorsNameExample
&Bitwise ANDa & b
|Bitwise ORa | b
^Bitwise XORa ^ b
~Bitwise complement~ b
<<Shift lefta<<1
>>Shift righta>>1
No Comments

Send Comment Edit Comment


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
Previous
Next