AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: JV — October 6, 2006
    +0 votes
      + -

    The loop will be executed until d reaches a null character

  2. Submitted By: sheen — October 6, 2006
    +6 votes
      + -

    string copy

  3. Submitted By: sheen — October 6, 2006
    +11 votes
      + -

    string copy utill zero appears

  4. Submitted By: octav_timofte — October 6, 2006
    +0 votes
      + -

    String copy is performed indeed but be careful with the space allocated for the destination string.
    Check this example:

    char s1[10]=”abcde”;
    char s2[3];

    char* c,*d;
    c=s2;
    d=s1;
    while(*c++ = *d++);
    printf(”%s - %sn”,s1,s2);

  5. Submitted By: johny1 — October 6, 2006
    -8 votes
      + -

    The code is string copy. But it does not add a null pointer to the end. There should also be a check for overlapping addresses.

  6. Submitted By: jobhunter — October 6, 2006
    -20 votes
      + -

    Where is a logical value being returned in the while(*c++ = *d ++)

    *c++ = *d++ is not a logical expression, hence incorrect syntactically.

    Isn’t it. Please correct me if i’m wrong.

  7. Submitted By: Mohit — October 6, 2006
    -1 votes
      + -

    String copy–for sure

  8. Submitted By: Hotshot — October 6, 2006
    -4 votes
      + -

    All that the basic operation :

    while (*c++ = *d++)
    ;

    does is to copy the destination string’s characters to the source string (here ‘d’ to ‘c’). In the above statement, one after another, the contents being pointed to by the destination pointer (’d') are faithfully copied into the source string, pointed to by (’c').

    Then the while condition is evaluated, which works on a boolean basis (TRUTH/FALSITY). In C, a true value is non-zero and false value is ‘0′.

    So, until the source string (’d') hits the end of the string, ‘’ (ASCII - 0), all the contents are copied into the string pointed to by (’c'), including the string delimiter ‘’, and evaluated by the while finally for truth/falsity.

    The above is a short form of writing :

    while (*c == *d) {
    c++;
    d++;
    }

  9. Submitted By: phil — October 6, 2006
    +5 votes
      + -

    jobhunter:

    *c++ = *d++
    evaluates to the char that was assigned to *c. This is the “boolean” value that while tests. So if this char is 0, then while fails; else it continues.

  10. Submitted By: neo_jack1 — December 5, 2006
    +0 votes
      + -

    it’s a string copy function.
    after assignment of null char to destination string only while loop fails.care should taken on the size of destination string.

  11. Submitted By: Arijit — July 15, 2007
    -2 votes
      + -

    char pointers initiated as a string is read only,U cannot write anything on that.so if c is declared as a type char *c=”hello”,
    then *c++=*d++ will not work.

  12. Submitted By: Matthew — February 13, 2008
    -1 votes
      + -

    This would either crash or would be an infinite loop because there is no breaking condition. So it doesn’t matter what c or d were.

  13. Submitted By: Anjali — February 17, 2008
    -2 votes
      + -

    I think that since no termination condition is given so it will go in a infinite loop no matter what s &d contains

  14. Submitted By: Raaz — March 7, 2008
    +1 votes
      + -

    The piece of code will not go in an endless loop.For ex: consider
    char str1[10] = “ABCDE”;
    char str2[10] = “FGHIJ”;
    char * c = str1;
    char *d = str2;
    while(*c++ = *d++);
    printf(”%s…%s\n”,s1,s2);
    Output will be FGHIJ…FGHIJ
    why because the condition copies each character one by one untilthe pointer encounters a NULL character in the array and as it is shown the character array str1 and str2 is of size 10 each and only 4 indexes are used (starting from 0) meaning remaining index values are considered as NULL. So the loop does terminate.

  15. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.