Tutorial(for beginners):Operators in C
Posted: Wed Aug 01, 2012 5:18 am
Hi.I didn't see any tutorial like this but a lot of begginer has problem with these.
For the purposes of this tutorial, a, b, and c represent valid values (literals, values from variables, or return value).
Arithmetic operators:
Basic assignment: a=b (Note:In the if statements it means: If a could be equal with b)
There is the Addition and the Subtraction but they are easy so everybody should know.
Multiplication: a * b
Division: a / b(if anyone don't know the operator of the multiplication or the division)
Modulo (integer remainder): a % b (ex. 11 % 5 = 1)
Operators that we use in the if statements:
Equal to: a == b(This is the correct way(and not this: a = b) in the if statement)
Not equal to: a != b
Greater than: a > b
Less than : a < b
Greater than or equal to: a >= b
Less than and equal to: a <= b
Logical operators :
Logical negation (NOT): !a
Logical AND: a = b && b = c
Logical OR a = b || b = c
Compound assignment operators:
Addition assignment a += b means -> a = a + b
Subtraction assignment a -= b means -> a = a - b
Multiplication assignment a *= b means -> a=a*b
Division assignment a /= b means -> a= a / b
Modulo assignment a %= b means -> a=a / b
For the purposes of this tutorial, a, b, and c represent valid values (literals, values from variables, or return value).
Arithmetic operators:
Basic assignment: a=b (Note:In the if statements it means: If a could be equal with b)
There is the Addition and the Subtraction but they are easy so everybody should know.
Multiplication: a * b
Division: a / b(if anyone don't know the operator of the multiplication or the division)
Modulo (integer remainder): a % b (ex. 11 % 5 = 1)
Operators that we use in the if statements:
Equal to: a == b(This is the correct way(and not this: a = b) in the if statement)
Not equal to: a != b
Greater than: a > b
Less than : a < b
Greater than or equal to: a >= b
Less than and equal to: a <= b
Logical operators :
Logical negation (NOT): !a
Logical AND: a = b && b = c
Logical OR a = b || b = c
Compound assignment operators:
Addition assignment a += b means -> a = a + b
Subtraction assignment a -= b means -> a = a - b
Multiplication assignment a *= b means -> a=a*b
Division assignment a /= b means -> a= a / b
Modulo assignment a %= b means -> a=a / b
- Code: Select all
[u]References:[/u]
http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B