You'll cut adrift elem object with data == 0 after the first iteration of the loop and lose access to it completely by the end of the loop:
step 1: 2 pointers p and p->next both pointing to elem object with data == 0
step 2: q(1) points to elem object with data == 1 and q(1)->next points to elem object with data == 0; p->next now points to elem object with data == 1 and p points to elem object with data == 1
So we have one pointer to elem object with data == 0, viz. q(1)->next and 3 pointers to the elem object with data == 1 viz. p, p->next and q(1) - notice q(1)->next is already starting to get cut off, if the loop ended here you could still access the object through q(1)->next but, as shown below, this will be lost in the next loop
step 3: q(2) points to elem object with data == 2 and q(2)->next points to elem object with data == 1. p->next points to elem object with data == 2 and p points to elem object with data == 2
So we have one pointer, q(1)->next, pointing to elem object with data == 0, two pointers, q(1) and q(2)->next pointing to elem object with data == 1 and three pointers (p, p->next and q(2)->next) pointing to elem object with data == 2. Of course q(2) is actually q in the program and as there is no linkage b/w q(1) next and any of the other pointers you cannot access elem object with data == 0 any longer
Here is a link to setting up a singly linked list:
http://www.cplusplus.com/forum/beginner/209045/#msg983899 and there will be many more on-line