My code is following
#include <iostream>
int main(int argc, char *argv[])
{
int i = 10;
char c[3];
std::cout << i << std::endl;
sprintf(c, "%d", i);
std::cout << i << std::endl;
return 0;
}
Result of it's execution:
10
10
Great, make scene. Let's make char array too small.
#include <iostream>
int main(int argc, char *argv[])
{
int i = 100;
char c[3];
std::cout << i << std::endl;
sprintf(c, "%d", i);
std::cout << i << std::endl;
return 0;
}
Result of it's execution:
100
0
How on Earth i
was changed? So sprintf() can change input variables? Why?