#include<stdio.h>
char *convert(int n)
{
char s[10] = "";
int i = 0;
int r = 0;
char *pp = s;
while (n>0)
{
r = n % 10;
s[i++] = r + '0';
n = n / 10;
}
//printf("%s\n", pp);
return pp;
}
int main()
{
int input = 123;
char *p;
p = convert(input);
printf("%s\n", p);
return 0;
}
Question: If I uncomment the printf() statement in convert() then only printf() in main() executes correctly.
Please explain.