I don't understand the output from this code:
#include <stdio.h>
long func(long pass)
{
long ret;
long i = pass;
if (i == 6)
{
printf("i=%ld\n",i);
return i;
}
printf("ended\n");
}
void main()
{
int j;
long it = 0;
for(j = 0; j < 12; j++)
{
printf("%ld\n",func(it));
it++;
}
}
The output shows "ended" and "6" every time except when it reaches i=6, that time it prints i=6 and 6.
WHY? It shouldn't be going inside i == 6 every time right?
funcdoesn't return anything unlesspass == 6. That's undefined behavior.i!=6, what would you consider to be the right value?warning: control reaches end of non-voidandwarning: return type of 'main' is not 'int'. Read that first