I have been asked to describe what these lines of code are doing for a college assignment
int main() { int t1[] = {0,0,1,1,1}, t2[] = {0,0,1,1,1}; int *p1 = t1, *p2 = t2; while (!*p1++ || !*p2++); cout << (p1-t1) << endl; cout << (p2-t2) << endl; } My take on it is, 2 arrays of type int are created and filled with values, 2 pointers are created and pointed at each array, then I start to have trouble.
while (!*p1++ || !*p2++); To me this is saying while 0 move the position of *p1one place or while 0 move the position of *p2 one place, I'm really not confident in that assumption?
cout << (p1-t1) << endl; So then we move onto the cout, now my take on this is, I'm subtracting the position of p1 from the position of t1, where p1 was positioned by the while and t1 points to the first position in the array. again I could be completely wrong I'm only learning about pointers so please bear this in mind if I'm wrong in my assumptions.
mainshould return anint. Some systems expect thatmainreturns0if and only if program finished his work succesfully. Whenmainreturnsvoid, when system will try to read the exit status, gets garbage."5\n3\n", but that isn't the important part.