Broken calculator

this is the code
#include
using namespace std;

int multiply( int *res, int x, int res_size)
{

int carry=0,i,prod;
for(i=0;i<res_size;i++)
{

prod=res[i]*x+carry;
res[i]=prod%10;
carry=prod/10;
}

while(carry)
{

res[res_size]=carry%10;
carry=carry/10;
res_size++;
}

return res_size;
}

int main() {
int n;
int res[500];
int res_size=1,x,i;
res[0]={1};
cin>>n;
if(n==1)
cout<<β€œ1”;
else
{

for (x=2;x<=n;x++)
res_size=multiply( res, x,res_size);
for (i=res_size-1;i>=0;i–)
cout<<res[i];
}

return 0;

}
this is the code i found but i honestly do not understand how it works so please explain

Change the size of res array to 2000

Bro I am not asking why this code is not passing test cases. I am asking I don’t understand how this works please explain

The answer of 500 factorial has more than 500 digits, so you need to increase the size of your res array to prevent overflow.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.