先定义全局的变量和类型,该方法只输出循环的最后一个值。
int J
源码
#include <stdio.h>
#define SIZE 4
int J;
int a[SIZE] = {1, 2, 3, 4};
int b[SIZE] = {1, 3, 5, 6};
int i;
int main()
{
for (i = 0; i < SIZE; i++)
{
J = 2;
// printf("a(%d) - b(%d) = %d \n", i, i, a[i] - b[i]);
}
printf("J================%d\n",J);
return 0;
}
执行结果:
J================:2
[Thread 9428.0x4c10 exited with code 0]
[Inferior 1 (process 9428) exited normally]
感叹号
#include <stdio.h>
#define SIZE 4
int J;
int a[SIZE] = {1, 2, 3, 4};
int b[SIZE] = {1, 3, 5, 6};
int i;
int main()
{
int R;
for (i = 0; i < SIZE; i++)
{
if (!a[i] < 3)
{
J = a[i];
}
R = 20;
// printf("a(%d) - b(%d) = %d \n", i, i, a[i] - b[i]);
}
printf("J================%d\n", J);
printf("R================%d\n", R);
return 0;
}
执行结果:
J================4
R================20
[Thread 25636.0xb9e0 exited with code 0]
[Inferior 1 (process 25636) exited normally]