To calculate the variance of x, we first notice that p is the mean of x, and if you look at the two possible outcomes starting with heads and then tails, you find that the probability for heads is p and if heads is chosen then the variance is the quadratic difference of the actual outcome, which is 1 for heads minus the mean which equals p. 