doubt ampersand
#1

Hello guys.

Well, I see in many codes, this:
pawn Код:
//exemple
stock Lyrics(&number, &lol)
This has the same function if I put it this way? :
pawn Код:
stock Lyrics(number, lol)
Does this change anything?...
Reply
#2

the & is to return multiple values
https://sampwiki.blast.hk/wiki/Stocks
Reply
#3

The ampersand means that the argument is to be passed as a reference, not as a value. If you pass arguments by value (the default) then the original value of the variable will not change. If you pass arguments by reference then they will. For example:
pawn Код:
new a = 42;

stock byRef(&value)
{
    value++;
}

byRef(a);
printf("%d", a);
Will print 43. Whereas:

pawn Код:
new a = 42;

stock byVal(value)
{
    value++;
}

byVal(a);
printf("%d", a);
Will still print 42.
Reply
#4

wow, ok.
Thanks to 2.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)