Can somebody explain me how the following tochar
function works? As an experiment I added the following to tochar
:
cout<<'0' + value
When run, I got a result of:
51 50 49 52
My code is:
static int tochar(int value)
{
return '0' + value;//This is the part i don't understand
}
int main()
{
char c[20];
int n = 4123;
int count = 0;
int number = log10(n)+1; //number of digits
for (int i = number; i >= 1; i--)
{
c[i] = tochar(n % 10);
n = n / 10;
count++;
}
for (int i = 1; i <=count; i++)
cout<<c[i];
system("pause");
}