Tutorial(for beginners):Operators in C

Learn how to make certain types of games and use gameEditor.

Tutorial(for beginners):Operators in C

Postby tzoli » 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

Code: Select all
[u]References:[/u]
http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: Tutorial(for beginners):Operators in C

Postby supatails » Wed Sep 05, 2012 4:17 am

This is really helpful and I reference it a lot, but just a quick question: is there any way to write "a through b"? For example, 2 through 16? Or do I have to write out
Code: Select all
2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15 || 16
User avatar
supatails
 
Posts: 43
Joined: Tue Aug 04, 2009 4:54 am
Score: 1 Give a positive score

Re: Tutorial(for beginners):Operators in C

Postby skydereign » Wed Sep 05, 2012 4:21 am

supatails wrote:This is really helpful and I reference it a lot, but just a quick question: is there any way to write "a through b"? For example, 2 through 16? Or do I have to write out
Code: Select all
2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15 || 16

You would never do that. That is just saying 2 or 3 or 4 and so on. That is always true. Perhaps you meant this?
Code: Select all
(var==2 || var==3 || var==4)

In which case you can use > and < to create ranges.
Code: Select all
(var>=2 && var<=16)
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Tutorial(for beginners):Operators in C

Postby supatails » Wed Sep 05, 2012 3:56 pm

Oh! XD That's really obvious! Thanks.
User avatar
supatails
 
Posts: 43
Joined: Tue Aug 04, 2009 4:54 am
Score: 1 Give a positive score


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron