//Testing program 1
#include <stdio.h>
int main(void)
{
int i,array[101]={0};
for(i=1;i<101;i++)
printf(" %d",array[i]);
return 0;
}
Following is the result.
What?It depends on the scale of the array?
I was puzzled,and modified the code like testing program 2.
//Testing program 2
#include <stdio.h>
int main(void)
{
int i,array[3]={0};
for(i=0;i<3;i++)
printf(" %d",array[i]);
printf("\n");
return 0;
}
The result is following.
It seemed that scale of the array did influence the result.To convince myself,testing program 3 came into being.Of course there were many other testing programs which I'm unable to show to you one after another.
//Testing program 3
#include <stdio.h>
int main(void)
{
int i,array[6]={0};
for(i=0;i<6;i++)
printf(" %d",array[i]);
printf("\n");
return 0;
}
And the result is following.
As expected,not all the elements equal 0.
How can we explain it?Maybe it's because different compilers deal with "int a[10]={0};" variously,I think.To avoid mistakes,why not write a loop statement?I'm sorry that I didn't want to write another circle statement,so the mistake appeared.But I feel lucky for learning so much from it.
Of course,if you understand the exact explanation of this mistake,welcome to post a comment or email me at jimzhou001@gmail.com.Thank you!
#include <stdio.h>
int main(void)
{
int i,array[101]={0};
for(i=1;i<101;i++)
printf(" %d",array[i]);
return 0;
}
Following is the result.
I was puzzled,and modified the code like testing program 2.
//Testing program 2
#include <stdio.h>
int main(void)
{
int i,array[3]={0};
for(i=0;i<3;i++)
printf(" %d",array[i]);
printf("\n");
return 0;
}
The result is following.
It seemed that scale of the array did influence the result.To convince myself,testing program 3 came into being.Of course there were many other testing programs which I'm unable to show to you one after another.
//Testing program 3
#include <stdio.h>
int main(void)
{
int i,array[6]={0};
for(i=0;i<6;i++)
printf(" %d",array[i]);
printf("\n");
return 0;
}
And the result is following.
How can we explain it?Maybe it's because different compilers deal with "int a[10]={0};" variously,I think.To avoid mistakes,why not write a loop statement?I'm sorry that I didn't want to write another circle statement,so the mistake appeared.But I feel lucky for learning so much from it.
Of course,if you understand the exact explanation of this mistake,welcome to post a comment or email me at jimzhou001@gmail.com.Thank you!
No comments:
Post a Comment