According to the links Rank and Trace and Projection Matrix, the rank of a matrix $X$ with entries in $\mathbb{R}$ can be computed by the equation
$$\text{rank} (X) = \text{tr}\left(X (X^TX)^{+}X^T\right) \hspace{20 mm} (1)$$ where $(X^TX)^+$ is the Moore-Penrose pseudo inverse of $X^TX.$
I have tested by simulations that the rank of a matrix $X$ with entries in $\mathbb{C}$ can be computed by
$$\text{rank} (X) = \text{tr}\left(X^+ X\right) \hspace{37 mm} (2)$$
Notice that $\text{tr}\left(X^+ X\right) = \text{tr}\left(XX^+\right)$ and equation $(1)$ can be obtained from $(2)$ if $X$ has full column rank, according to the link Moore-Penrose pseudo inverse.
I want to answer the following questions:
$(a)$ How to prove that equation $(2)$ always holds (or not)?
$(b)$ How to derive equation $(1)$ from $(2)$ when $X$ is not full column rank?
I just need some hints. Thanks in advance!