神秘现象?多种情况比较
先看以下代码:
1
#include <stdio.h>
2
#include <string.h>
3
4
5
6
int main()
7
{
8
int N = 0;
9
int subValue = 0,MaxValue = 0;
10
int iN = 0,jN = 0;
11
int si,sj;
12
int i,j;
13
int ii,jj;
14
15
16
int Matrix[100][100];
17
18
scanf("%d",&N);
19
for(iN = 0;iN<N;iN++)
20
{
21
for(jN = 0;jN<N;jN++)
22
{
23
scanf("%d",&Matrix[iN][jN]);
24
}
25
}
26

27
}
将断点设在18行后,输入4,检查N的值,居然是:
#include <stdio.h>2
#include <string.h>3

4

5

6
int main()7
{8
int N = 0;9
int subValue = 0,MaxValue = 0;10
int iN = 0,jN = 0;11
int si,sj;12
int i,j;13
int ii,jj;14
15
16
int Matrix[100][100];17

18
scanf("%d",&N);19
for(iN = 0;iN<N;iN++)20
{21
for(jN = 0;jN<N;jN++)22
{23
scanf("%d",&Matrix[iN][jN]);24
}25
}26


27
}改变代码:
#include <stdio.h>
#include <string.h>
int Matrix[100][100];
int subValue = 0,MaxValue = 0;
int iN = 0,jN = 0;
int si,sj;
int i,j;
int ii,jj;
int main()
{
int N = 0;

scanf("%d",&N);
for(iN = 0;iN<N;iN++)
{
for(jN = 0;jN<N;jN++)
{
scanf("%d",&Matrix[iN][jN]);
}
}

}而唯一正常的是如下代码:
即将所有N在函数体外声明便正常了,难道是C语言对函数体内的变量有个数限制?神秘现象解密中...
posted on 2006-11-26 21:37 wqlblogger 阅读(226) 评论(0) 收藏 举报

浙公网安备 33010602011771号