arrays - C++ assignment operator in while -
can explain how piece of code works? assignment operator in while not mistake, did on purpose. if put n values in str1, output n*2-1 stars. in case, output 0 stars.
the code in main is:
char str1[] = ""; char str2[10]; char *p1 = str1; char *p2 = str2; while(*p2++ = *p1++) cout << "* "; return 0; thanks in advance!
the conditional of while statement can thought of as:
(*p2++ = *p1++) != 0 which can thought of as,
(*p2++ = *p1++), *(p2-1) != 0 since p2 post-incremented in line.
the loop continue until null character string p1 points copied string p2 points to.
Comments
Post a Comment