/* ptrArith_4.c same as 3 but we condense the syntax to its minimal form via a while loop and eliminate the explicit '\0' assignment after the loop */ #include #include #include #define WORD_LENGTH 30 int main(int argc, char *argv[]) { char word[WORD_LENGTH]; char *name = (char *)malloc(WORD_LENGTH * sizeof(char)); char *word_ptr = word, *name_ptr = name; /* the start of each string */ strcpy(name, "Professor"); while (*word_ptr++ = *name_ptr++); /* THIS IS IT!!! */ /* Question: Why don't we need to copy a null onto the end after the loop finishes? Answer: Because the assignment must complete from right to left and then the value returned is evaluated to be true or false by the loop */ printf("My name is: %s\n", word); return 0; }