![](/img/trans.png)
[英]Getting incorrect output when I implement merge sort with threads, can't figure out what's wrong
[英]what happens when function doesnt explicitly return a value? can't figure out how the output of the code is coming
我在一個測試系列中遇到了一個問題,當我根據我對 C 編程的知識手動解決時,應該給出一個 output 與給定的任何選項都不匹配。
我的 output = '++++'
問:c程序的Output是什么?
#include <stdio.h>
int f(int x)
{
if(x==2){ return 2; }
else{ printf("+"); f(x-1); }
}
int main()
{
int n = f(6);
printf("%d",n);
return 0;
}
選項:
我的邏輯:因為最后 f(6) 沒有顯式返回任何內容[只有 f(2) 將值 2 返回到 f(3)],output 應該只包含 4 次“+”,因為每次調用 f (6)、f(5)、f(4) 和 f(3)。
以下是我在在線 c 編譯器 - 'codechef' 和 'onlinegdb' 上嘗試過的一些測試代碼及其輸出屏幕截圖 - 但我也無法理解它們的輸出。 請幫忙!
編解碼器
在線gdb 1
在線gdb 2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.