What will be the output of the following C code?
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
ungetc(n, stdin);
scanf("%d", &n);
printf("%d\n", n);
return 0;
}
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
ungetc(n, stdin);
scanf("%d", &n);
printf("%d\n", n);
return 0;
}
A. Compile time error
B. Whatever is typed by the user first time
C. Whatever is typed by the user second time
D. Undefined behaviour
Answer: Option B
Join The Discussion