I am working on code and I tried to type char instead of integer, and the result was "2" regardless of the character entered, is this behavior undefined or something else?
The code:
#include <stdio.h>
int f1(int n);
int f2(void);
int main(void)
{
int t;
printf("Enter a number: ");
scanf("%d", &t);
t ? f1(t) + f2() : printf("zero entered.\n");
return 0;
}
int f1(int n)
{
printf("%d ", n);
return 0;
}
int f2(void)
{
printf("entered.\n");
return 0;
}
when I entered a, the result was “2 entered”, and when I entered g, the result was “2 entered”, and when I entered i,h,k,....., the result was the same. What is it?
source
share