

The second question:

Books if a character array of deposit has a number of different length of string, you should make the longest length is greater than the length of the string array, why char [0] can also

#include
#include
Int main ()
{
Char c []={" c program "};
Char [] d={} "Hello";
Char [] e={' C ', ', 'p', 'r', 'o', 'g', 'r', 'a', 'm'};
int i;
for(i=0; i<=4; I++)
C=d [I] [I];
Puts (c);
Puts (e);
return 0;
}
#include
Int main ()
{
Char [] e={' C ', ', 'p', 'r', 'o', 'g', 'r', 'a', 'm'};
//for (I=0; i<=8; I++)
Puts (e);
}
#include
Int main ()
{
Char a, [0].
//to save "abcd" in a
Strcpy (a, "abcde");
//output string in a
Puts (a);
//will be "1234" save in a
Strcpy (a, "1234");
//output string in a
Puts (a);
}
CodePudding user response:
#include
#include
Int main ()
{
Char c []={" c program "};
Char [] d={} "Hello";
Char [] e={' C ', ', 'p', 'r', 'o', 'g', 'r', 'a', 'm'};
int i;
for(i=0; i<=4; I++)
C=d [I] [I];
Puts (c);
Puts (e);
return 0;
}
#include
Int main ()
{
Char [] e={' C ', ', 'p', 'r', 'o', 'g', 'r', 'a', 'm'};
//for (I=0; i<=8; I++)
Puts (e);
}
#include
Int main ()
{
Char a, [0].
//to save "abcd" in a
Strcpy (a, "abcde");
//output string in a
Puts (a);
//will be "1234" save in a
Strcpy (a, "1234");
//output string in a
Puts (a);
}
CodePudding user response:

Why is beyond 5 bytes or not warning?
#include
Int main ()
{
Char STR [5].
Gets (STR);
Puts (STR);
return 0;
}
CodePudding user response:
Occupy the static data partition, because there is no defined end, puts the actual cross-border access may occur, this show at randomCodePudding user response:
In addition, the usage gets here is not credible, can inject illegal string, produce coredump memoryCodePudding user response:

Changed to printf is stil
#include
#include
Int main ()
{
Char c []={" c program "};
Char [] d={} "Hello";
Char [] e={' C ', ', 'p', 'r', 'o', 'g', 'r', 'a', 'm'};
int i;
for(i=0; i<=4; I++)
C=d [I] [I];
Printf (" % s \ n ", c);
Printf (" % s \ n ", e);
return 0;
}
CodePudding user response:


Why is that? Why don't the second warning?
CodePudding user response: