Home > Software engineering >  Why to write long character array character will not go wrong?
Why to write long character array character will not go wrong?

Time:10-10

# include "stdafx. H"
#include

Int main ()
{
Char a, [8].//define length is 8
Size_t I;
I=_snprintf (a, 13, "% d" 012, 123456789);//write length of 12 characters
The printf (a);//print to window shows 000123456789
printf("\n");
system("pause");
return 0;
}

Define a length of only eight, run results either an error or print only eight characters before yes, why is printed to the window of super-long character?

CodePudding user response:

Char a [8] data overflow will affect other variables such as size_t I

CodePudding user response:

Recommend using _s function, _snprintf_s



  • Related