我现在正在学习C编程语言并尝试理解其中的函数。 下面的代码在 Visual Studio 中不会给出错误,并返回发送到该函数的第一个参数。 我认为它应该给出一个错误,但它没有。
给定的代码如何工作以及如何返回代码中的第一个参数 3?
#include <stdio.h>
#include <stdlib.h>
int hesapla(int x, int y);
void f();
int main()
{
int a, b, sonuyc;
int s;
printf("\n");
printf("sonuc = %d", hesapla(3, 10));
system("pause");
return 0;
}
int hesapla( int x, int y) {
if (x > y )
return y;
if (x == y)
return y + 1;
}
谢谢你..
最佳答案
您的函数hesalpha
不return
任何时候x < y
因此,它表现出未定义的行为。
您可以使用if else
来处理这种情况。或者只是 return
当前面的两个条件都为 false 时,默认值。
关于c - c中无法访问的语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34452961/