In your question, c is declared as a whole. therefore, it crosses the limit of the whole in the expression c * (c-1). therefore, overflow occurs. Before it is implicitly converted to long long.Thats the reason for UB.
then when u implicitly converted it to long long u, you get the correct answer ...
source
share