Posts: 242
Threads: 70
Joined: Aug 2015
Reputation:
0
How do you actually tell to someone what's a sizeof is ? in my words it's just returning a string on arrays, is that right?
Posts: 6,242
Threads: 8
Joined: Jun 2008
It's working on how many cells are in the array.
Each character in a string is assigned a cell.
A string with the name Hello in it, would only need a string 5 long, and if it were str[5] and if we checked what str[2] was we'd end up with l (Or e... unsure on what it will return, but the 'address' is to the one character sitting in 2).
Sizeof isn't returning the string, it's simply returning the actual size of the array.
Posts: 1,801
Threads: 21
Joined: Mar 2008
Reputation:
0
Also it's good to know that sizeof is a compiler directive, so it's not a function (unlike strlen for example). That implies you cannot use it on arrays with a size that's not known at compile-time (function arguments mostly).
That's why functions which write into arrays also need the size of the array passed seperately (like format).
It can be used on any variable as well, it doesn't neccessarily have to be an array (however there's almost no use-case except arrays, as all variables in PAWN are cells).