Raised This Month: $51 Target: $400
 12% 

= help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-22-2008 , 17:11   = help
Reply With Quote #1

everyone knows that "=" means "equals", but does that mean i could do this:
Code:
new x, y;
x = y = 5;
then x and y would equal 5?

thats not my code exactly, but thats what im trying to accomplish is that two variables would equal the same value with 1 statement.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-22-2008 , 17:16   Re: = help
Reply With Quote #2

You can.

But why did not you tested, instead of posting here ? It takes few seconds to see by yourself...
__________________

Last edited by Arkshine; 01-22-2008 at 17:20.
Arkshine is offline
[kirk]./musick`
Senior Member
Join Date: Jun 2007
Location: Tampa, Florida
Old 01-22-2008 , 17:31   Re: = help
Reply With Quote #3

Now x equals what y equals (5).
__________________
[kirk]./musick` is offline
Send a message via AIM to [kirk]./musick`
_Master_
Senior Member
Join Date: Dec 2006
Old 01-22-2008 , 21:48   Re: = help
Reply With Quote #4

That's not exactly how it works kirk...

Simply put the expression is valuated from right to left. "y = 5" valuates to "5". Then "x = <5>" again valuates to "5" which means that the entire expression valuates to "5".

This can be used for other purposes as well.
Ex: "if( x = y = A < 7 )" The condition will be true if A < 7.
Ex: "x = y = x - y" is identical to "y = x - y; x = y"

You can make an undefined chain of initializations like this. Just make sure those are l-values,
except for last op which can be a r-value ( ie. you can't make a statement like "x = y - 2 = 5" because "y - 2" is not a l-value )

Same rule applies here: "if( fp = fopen( ... ) )" tho the AMXX compiler will give a warning about a possible incorrect assignment.

Last edited by _Master_; 01-22-2008 at 22:49.
_Master_ is offline
[kirk]./musick`
Senior Member
Join Date: Jun 2007
Location: Tampa, Florida
Old 01-23-2008 , 07:20   Re: = help
Reply With Quote #5

Ah, but it still evaluates to the same value.
__________________
[kirk]./musick` is offline
Send a message via AIM to [kirk]./musick`
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 16:32.


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