#include
Int main ()
{
Int a []={0};
//int a [10]={0}.
for (int i=0; I & lt; 10; I++)
{
Printf (" % d ", a [I]);
}
return 0;
}
Why is printed: 0-858993460, 77177290, 5241112, 19865779 1 8408400 8409552 1 8408400
Directly define array length can be printed out? if not first define the length a accurate print out what's the solution? Thank you very much!
CodePudding user response:
Annotation inside out, and the int a [10]={0} comments can be removed,CodePudding user response:
# include
#include
Int main (int arg c, char * argv [])
{
//int a []={0}.
Int a [10]={0};//array of fixed length and initialized to 0
int m;
The scanf (" % d ", & amp; M);
Int * b=new int [m].//the first dynamic array length
Int * c=(int *) malloc (sizeof (int) * m);//the second dynamic array length
Memset (b, 1, m * sizeof (b));//initialize an array of 1 b
Memset (c, 0, m * sizeof (c));//initialize array c 0
//for (int I=0; I & lt; m; I++)//loop initialization array
//{
[I]//b=c [I]=0;
//}
for (int i=0; I & lt; m; I++)//when m> 10, after a [10] shows is uncertain value, crossed the
{
Printf (" a [% d]=% 15 d \ [% d] TB - 15 d=% \ tc [% d]=% 15 d \ n ", I, a [I], I, b [I], I, c [I]);
}
system("pause");
The delete [] b;//dynamic release
B=NULL:
Free (c);
C=NULL;
return 0;
}
CodePudding user response: