1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

A doubt regarding a Piece of code!!! ple. help

Discussion in 'C' started by vikky1988i, Apr 25, 2011.

  1. vikky1988i

    vikky1988i New Member

    Joined:
    Apr 1, 2010
    Messages:
    25
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Mainframes Admin. @ I | Nautix Technologies
    Location:
    chennai , Tamil Nadu ,INDIA
    Hello all,
    I have a problem in understanding a basic thing in this code!!!

    while(*src++ = *des++);

    seems to run infinitely since no condition here , but in real this works fine.... just need a explanation for this.. how does the compiler interprets this!!! please :snobby::embarasse:worried:
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    while takes a boolean, so when *src++=*des++ evaluates to zero, the loop will terminate. The value of an expression is the assigned value, so for example if taken in a value context, the value of "a=5" is 5. So this also means you can do something like a=b=c=d=e=3; which will set all variables to the same value.
     

Share This Page