What is the rule for computing $ \text{E}[X^{2}] $, where $ \text{E} $ is the expectation operator and $ X $ is a random variable?

Let $ S $ be a sample space, and let $ p(x) $ denote the probability mass function of $ X $.

Is $$ \text{E}[X^{2}] = \sum_{x \in S} x^{2} \cdot p(x), $$ or do I also need to square the $ x $ appearing in $ p(x) $?