C Operators – Logical, Arithmetic, Relational

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/c-operators-logical-arithmetic-relational/
PINTEREST
PINTEREST
INSTAGRAM

C Programming Tutorial Index

  1. Introduction To Programming
  2. C Setup Development Environment
  3. C Hello World and Compile First Application
  4. C Syntax and Basics
  5. C Variables
  6. C Numeric Variable Types (Integer, Long, Float)
  7. C String Variables
  8. C Constants and Define Processor
  9. C Operators
  10. C If Else and Switch Case Conditionals
  11. C While Loops
  12. C For Loops
  13. C Arrays
  14. C Functions
  15. C Structure
  16. C Union
  17. C File Operations (Open, Read, Write)
  18. C Pointers
  19. C Type Casting
  20. C Header Files and Include

Operators are leg and arm of the C programming language. A lot of operations done with operators. Operators used to assign, sum, subtract, multiply, divide, remainder, increment, decrement … operations. We will look all of these operations in this chapter. Operators can be grouped like below.

  • Arithmetic
  • Relational
  • Logical
  • Bitwise
  • Assignment
  • Misc

Arithmetic

Arithmetic is most popular usage of operators. Add, Subtract, Multiply, Divide, Modulus, Increment, Decrement operations can be done with arithmetic operators.

Add

Add operator is + as expected. In the following example two numbers are added and assigned to a variable.

OR

Subtract

As usual as subtraction we know which is  -

OR

Multiply

Multiply operation can be done with * operator.

OR

Divide

Divide operation can be done with / . The result can not decimal.

OR

Modulus

Modulus operator will return the remainder or module operation result of two value.

OR

Increment

Increment operator will increment given variable only.

OR

Decrement

Decrement operation is the reverse of increment. Given variable will be decremented by one with -- operator like below.

OR

Relational

Relational operators generally used to compare two variables about their value. Below relational operators can be found.

Equal

Equal operator will check values of given variables. If these values are equal true will be returned, if their values are not equal false will be returned. Equal operator is expressed as ==

(a == b) will return true

(a == b) will return false

Not Equal

Not equal operator is used to compare variables and return true if they are different, returns false if they are same. Not equal operator is expressed as !=

(a != b) will return true

(a == b) will return false

Greater

Greater operator is used to test id one variable is greater  then other. Greater operator can be expressed with >

In this situation a>b will return false because b is greater than a

In this situation a>b will return true because a is greater than b

Lower

Lower operator is used to test id one variable is lower  then other. Lower operator can be expressed with <

In this situation a<b will return true because b is lower than a

In this situation a>b will return false because a is lower than b

Equal or Greater

Equal or Greater operator is similar to greater operator with addition to check equality with greatness. Equal or great will check if variables are equal or greater

This will return true because two variables are equal which is acceptable by our operator.

LEARN MORE  C Variables and Definition

Equal or Lower

Equal or Lower operator is similar to lower operator with addition to check equality with lowness. Equal or lower will check if variables are equal or lower

This will return true because two variables are equal which is acceptable by our operator.

Logical

Logical operators are important part of decition making. They are generally used with if, for, while keywords where we will look next chapters in detail.

And

And operator is a logical operator. And operator is expressed with &&

Or

Or is a logical operator. Or operator can be expressed with ||

Not

Not operator is used with logic true and false . Not will revert given value

Bit-wise

Bitwise operators are used to change variables with binary operations.

Binary And

This operation will And two variables in a binary manner with their binary presentations.

Binary Or

This operation will Or two variables in a binary manner with their binary presentations.

LEARN MORE  Python Variables and Types

Binary Xor

This operation will Xor two variables in a binary manner with their binary presentations.

Binary One Complement

This operator will complement variables in binary form

Binary Left Shift

This operator will shift specified step left the binary presentation of variable.

Binary Right Shift

This operator will shift specified step right the binary presentation of variable.

Assignment

Assignment is a popular operator used most of time for numerical operations.

C Programming Tutorial Index

  1. Introduction To Programming
  2. C Setup Development Environment
  3. C Hello World and Compile First Application
  4. C Syntax and Basics
  5. C Variables
  6. C Numeric Variable Types (Integer, Long, Float)
  7. C String Variables
  8. C Constants and Define Processor
  9. C Operators
  10. C If Else and Switch Case Conditionals
  11. C While Loops
  12. C For Loops
  13. C Arrays
  14. C Functions
  15. C Structure
  16. C Union
  17. C File Operations (Open, Read, Write)
  18. C Pointers
  19. C Type Casting
  20. C Header Files and Include
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/c-operators-logical-arithmetic-relational/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.