简单的c程序不打印输出

sou*_*der 2 c console

我有一个简单的c程序

#include <stdio.h>

int add(int, int);
int add (int a, int b) {
   return a+b;
}

int main(void) {
  int a, b, c;

  printf("Enter the 1st number ");
  scanf("%d",&a);
  printf("Enter the 2nd number ");
  scanf("%d",&b);
  c = add(a, b);
  printf("The value is %d ", c);
  return (0);
}
Run Code Online (Sandbox Code Playgroud)

我正在编译程序,cc main.c 当我运行程序./a.out
时,控制台中没有任何输出。

小智 6

出于性能原因,输出被缓冲。代替

printf("The value is %d ", c); 
Run Code Online (Sandbox Code Playgroud)

printf("The value is %d\n", c);
Run Code Online (Sandbox Code Playgroud)

或使用fflush(stdout);.

请参阅为什么 printf 在调用后不会刷新,除非格式字符串中有换行符?