Q:

Weird while loop with an assignment operation C++

I've seen the following snippet in a leetcode solution. It counts the number of elements in a linked list. The while statement just has an assignment operation. Can anyone explain how this works. 
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */

struct ListNode * temp = head;
int num = 1;
while(temp = temp->next){
    num++;
}

A:

the value of temp->nextis assigned to temp
while(temp) is evaluated (as temp != NULL)
in case the loop body is executed

Note: if head is NULL your program will face a runtime error 

