Code:
#include <stdio.h>
int fx(int a);
int main(void)
{
int x;
printf("Enter an integer: ");
scanf("%d", &x); /* assume user enters 5 */
switch( x )
{
case 8: printf("%d\n", fx(4) );
case 6: printf("%d\n", fx(6) );
case 5: printf("%d\n", fx(8) );
case 3: printf("%d\n", fx(10) );
default: printf("%d\n", fx(12) );
}
}
int fx(int a)
{
return (a - 4);
}
Output
Ok, I have no clue how the program gets the output. First I thought that for each of the cases, it gives a number to use as 'a'. But then I cant see how the number 5 activates 4, 6, and 8. Can someone explain it to me?