sizeof
#1

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?
Reply
#2

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.
Reply
#3

Thanks, appreciated
Reply
#4

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).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)