Raised This Month: $ Target: $400
 0% 

Difference between ++var and var++ ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kotinha
Senior Member
Join Date: Jun 2009
Location: Alentejo, Portugal :)
Old 11-13-2011 , 08:49   Difference between ++var and var++ ?
Reply With Quote #1

As the title says, what is the difference between doing ++var and var++ ?

I've been searching but found nothing...
__________________
"If God exists, I hope he has a good excuse." - Woody Allen
kotinha is offline
Flipper_SPb
Senior Member
Join Date: Jun 2009
Location: Worldspawn
Old 11-13-2011 , 09:12   Re: Difference between ++var and var++ ?
Reply With Quote #2

preincrement
x = ++var
means:
PHP Code:
var = var + 1
= var 
postincrement
x = var++
means:
PHP Code:
= var
var = var + 

__________________
Полный похуизм.
Flipper_SPb is offline
Send a message via ICQ to Flipper_SPb
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 11-13-2011 , 09:48   Re: Difference between ++var and var++ ?
Reply With Quote #3

You can find the answer here too : http://wiki.amxmodx.org/Pawn_Tutorial#Expressions
__________________
Arkshine is offline
kotinha
Senior Member
Join Date: Jun 2009
Location: Alentejo, Portugal :)
Old 11-13-2011 , 10:05   Re: Difference between ++var and var++ ?
Reply With Quote #4

So, it works like this?:
PHP Code:
new var1 10
new var2 var1++ // var2 = 10 and var1 = 11 ?
// -------
new var1 10
new var2 = ++var1 // var2 = 11 and var1 = 11 ? 
__________________
"If God exists, I hope he has a good excuse." - Woody Allen
kotinha is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-13-2011 , 10:07   Re: Difference between ++var and var++ ?
Reply With Quote #5

It determines the return value of var; var++ gives you the value prior to the increment while ++var gives you the value after the increment.

var = 10
x = var++
x = 10, var = 11

var = 10
x = ++var
x = 11, var = 11
__________________

Last edited by Bugsy; 11-13-2011 at 10:09.
Bugsy is offline
kotinha
Senior Member
Join Date: Jun 2009
Location: Alentejo, Portugal :)
Old 11-13-2011 , 10:29   Re: Difference between ++var and var++ ?
Reply With Quote #6

Alright, got it
Thanks
__________________
"If God exists, I hope he has a good excuse." - Woody Allen
kotinha is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode