如果该函数未真正提供一个函数,则该函数调用的返回值是多少?

编程入门 行业动态 更新时间:2024-10-11 23:27:58
本文介绍了如果该函数未真正提供一个函数,则该函数调用的返回值是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我们有以下代码:

int func(char str[], int len) { // Don't return anything here. } int main() { char str[] = "Hello"; int result = func(str, strlen(str)); printf("%d\n", result); }

它将在我的计算机上打印一些字符串值-1679929632.当我执行时,它会不时发生变化.

It will print some string value -1679929632 on my computer. And it changes from time to time when I execute.

任何人都可以解释为什么会发生这种情况吗?

Can anyone explain why this happen?

推荐答案

如果函数定义中没有return语句,则在执行被调用函数的最后一条语句后,控件会自动返回到调用函数.在这种情况下,被调用函数的返回值为未定义.如果不需要返回值,则将函数声明为无效返回类型;否则,返回0.否则,默认返回类型为int.

If no return statement appears in a function definition, control automatically returns to the calling function after the last statement of the called function is executed. In this case, the return value of the called function is undefined. If a return value is not required, declare the function to have void return type; otherwise, the default return type is int.

如上所述,它是未定义的,因此在返回某个随机值后找出根本原因是没有用的.

As mentioned above its undefined so finding root cause behind some random value as return will be useless.

更多推荐

如果该函数未真正提供一个函数,则该函数调用的返回值是多少?

本文发布于:2023-11-27 22:22:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639830.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   返回值   则该   一个函数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!