c - c中无法访问的语句

标签 c function return-value

我现在正在学习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;  

}

谢谢你..

最佳答案

您的函数hesalphareturn任何时候x < y因此,它表现出未定义的行为

您可以使用if else来处理这种情况。或者只是 return当前面的两个条件都为 false 时,默认值

关于c - c中无法访问的语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34452961/

相关文章:

C++ #include 外部函数问题

sql-server-2008 - 如何将值从动态 SQL 存储过程返回到 Entity Framework ?

ruby - 我的 Ruby 条件是什么?

c - 为什么使用此 C 代码会出现段错误?

c - STM32F 使用 HAL_CAN 库

c - 如何编写没有 'main'的C程序?

C++ linux 套接字在单个调用中将字符串数组(char **)作为连接字符串发送

C - 修改函数参数

javascript - 我如何调整此功能以将两位数减少到一位数?

javascript - 从不同的 HTML 标签中获取多个对应的值以在一个函数中使用