
[英]Why am I getting the error “using uninitialized memory 'i'” and “uninitialized local variable 'i' used” when trying to make i = i*i
[英]I keep getting the error "uninitialized local variable '_ 'used" even though in if statements I initialize variables [closed]
这是我编写的程序,试图找到 4 个整数中的最大和最小。 如果我确实在 if 语句之前定义了变量,它会删除错误但只给我原始数字,完全不受影响。
int I, II, III, IV;
printf("Enter four different integers: ");
scanf("%d %d %d %d", &I, &II, &III, &IV);
int s, l;
if (I > II)
{
I = l;
II = s;
}
else
{
I = s;
II = l;
}
if (III > s)
{
if (l < III)
{
III = l;
}
}
else
{
III = s;
}
if (IV > s)
{
if (l < IV)
{
IV = l;
}
}
else
{
IV = s;
}
printf("\nLargest: %d\n", l);
printf("Smallest: %d\n", s);
复制错误的方法:
int I;
int a = 1;
a = I;
赋值运算符将右手边的值复制到左手边的变量中。
您必须交换所有使用=
的左手和右手运算符。
例如,你应该写s = I;
而不是I = s;
.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.