I was writing a program for infix to postfix conversion in C. In that I wrote this helper function.
int prec(char op) {
switch(op) {
case '+':
case '-':
return 1;
case '*':
case '/':
return 2;
case '^':
return 3;
}
}
To that I mistakenly passed a char other than those mentioned there. It didn't raise any errors and I took a lot time to detect it.
Even though I didn't mention anything for other cases, it is returning an int value. Also I suppose that it is not a garbage value, because for same input, it is giving same output in multiple runs (Eg: prec('&') -> 38
). Someone please explain what is happening here.