Why is sizeof called a compile-time operator?
Because, at compile time, the compiler calculates the sizeof the expression and substitutes that compile-time constant value.
Isn't it actually a run-time operator?
You can even use
sizeof to evaluate the size of expressions you can't legally execute (ie, that would incur Undefined Behaviour), so long as the compiler can figure out what the type of the expression is.
Also, even before C++11
constexpr, you can use
sizeof expressions in ways you can't use run-time expressions.
And if it is indeed a compile-time operator, how does it help in producing portable code ...
Types may vary in size on different platforms. Using
sizeof expressions instead of hard-coded assumptions means your code won't break when you compile on a different platform and your types change size.