If we are given eigenvalues of a square matrix can we identify the rank of a matrix? I know that for every square matrix $A$ $\exists$ a non- singular matrix $P$ of same order such that $P’AP = D$ where  $D =Diag \begin{pmatrix} d_1 ,d_2 , \cdots, d_n\end{pmatrix}$.
Number of non-zero $d_i$ is equal to the rank of the matrix $A$  and $d_i$ 's are eigenvalues .
But if we only know that $r$ eigenvalues are non-zero can we conclude that $rank(A) =r$ ? How can it be possible ?
 A: You can if $A$ is diagonalizable. In fact, you know that the rank of the matrix is equal to
$$r(A) = n - \text{dim} \ Ker (A)$$
If the matrix is diagonalizable, it means that the dimension of Ker(A) is equal to the number of $0$ eigenvalues[0]; therefore if there are $r$ non-zero eigenvalues, it means that $\text{dim} \ Ker (A) = n - r$ and 
$$r(A) = r$$
[0] More precisely, it means that the geometric dimension of every eigenspace is equal to the multiplicity of the eigenvalue as a root of the charachteristic polynomial. 
A: Note that your first statement is not quite right, not every square matrix is diagonalizable. For example $$\begin{bmatrix} 1 & 1 \\ 0 & 1\end{bmatrix}$$ is nonsingular but it is not diagonalizable.
Now consider a matrix that is not diagonalizable,
$$\begin{bmatrix} 0 & 1 \\ 0 & 0\end{bmatrix}$$
We can see that there is no non-zero eigenvalues, but its rank is $1$. 
Compare it with 
$$\begin{bmatrix} 0 & 0 \\ 0 & 0\end{bmatrix}$$
This matrix has non non-zero eigenvalues, but its rank is $0$.
Hence with eigenvalues alone, we can't conclude about the rank of a matrix in general. 
In the event that the matrix is not diagonalizable, there is another decomposition of matrix known as Jordan canonical form. 
$\exists P$, $P^{-1}AP = J=diag(J_1, J_2, \ldots, J_k).$
Where $J_i = \begin{bmatrix} \lambda_i & 1 & & \\  &\lambda_i & \ddots & \\& &\ddots & 1 & \\ & & & \lambda_i  \end{bmatrix}$
Suppose $J_i$ has $p_i$ rows,  $\lambda_i \neq 0$, $rank(J_i)=p_i$
However if $\lambda_i = 0$, $rank(J_i)=p_i-1$, hence even if the eigenvalue is $0$, it might contribute to rank count of the matrix in general. 
When things are diagonalizable, each Jordan blocks are of size $p_i=1$ ($p_i-1=0$, the Jordan block corresponding to the zero eigenvalue can't contribute to the rank count) and hence it is possible to tell the rank easily with the information of number of non-zero eigenvalues directly. 
Remark: If you tell me the number of Jordan blocks that correspond to the $0$ eigenvalue, we are able to tell the rank. 
