please help :wierd in c

what are the reasons for differences in output
/////////////////
int i=0;
for(;i;)
{printf("abc"); /*gives no output*/
}


for(;0;)
{printf("abc"); /*but this gives output once*/
}

why does the two versions differ????
i thought that the second one also should not print anything
but actually it is printing once
i can't understand why?

Comments

  • : what are the reasons for differences in output
    : /////////////////
    : int i=0;
    : for(;i;)
    : {printf("abc"); /*gives no output*/
    : }
    :
    :
    : for(;0;)
    : {printf("abc"); /*but this gives output once*/
    : }
    :
    : why does the two versions differ????
    : i thought that the second one also should not print anything
    : but actually it is printing once
    : i can't understand why?
    :


    They don't differ, neither will give any output.
  • but this
    gives output
    i use turboc 3
    i tested it on many computers and
    the2nd one does give output once
    :

  • : what are the reasons for differences in output
    : /////////////////
    : int i=0;
    : for(;i;)
    : {printf("abc"); /*gives no output*/
    : }
    :
    :
    : for(;0;)
    : {printf("abc"); /*but this gives output once*/
    : }
    :
    : why does the two versions differ????
    : i thought that the second one also should not print anything
    : but actually it is printing once
    : i can't understand why?

    Using GCC on Linux gives no output.
  • : : what are the reasons for differences in output
    : : /////////////////
    : : int i=0;
    : : for(;i;)
    : : {printf("abc"); /*gives no output*/
    : : }
    : :
    : :
    : : for(;0;)
    : : {printf("abc"); /*but this gives output once*/
    : : }
    : :
    : : why does the two versions differ????
    : : i thought that the second one also should not print anything
    : : but actually it is printing once
    : : i can't understand why?
    :
    : Using GCC on Linux gives no output.
    :
    [blue]
    Im suspecting TurboC produces different opcodes for the second for loop then most other 32bit compilers, coinsidering that TurboC produces different results (ie, the second loop is printing once, while most other compilers it does not).

    In fact, shouldnt a 32bit compiler ignore that code and optomise it out?
    [/blue]
  • : but this
    : gives output
    : i use turboc 3
    : i tested it on many computers and
    : the2nd one does give output once
    : :
    :
    :


    That may be because TC3 is non-standard DOS crap that was best-before 1995. Get an ANSI/ISO C/C++ compiler and try the code there.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories