Let $k$ be a field and let $A$ be an $n \times n$ matrix with entries in $k$ (so that the powers $A_{i}$ are defined).
If $f (x)$ = $c_0$ + $c_1x$ +···+ $c_m x^m$ ∈ $k[x]$, define $f (A)$ = $c_0 I$ + $c_1A$ +···+ $c_m Am$.
Q: Give examples of $n \times n$ matrices $A$ and $B$ such that $k[A]$ is a domain and $k[B]$ is not a domain.
Thank you for your help and not commenting about asking just the question as stated.
For $A$, take $\;\begin{pmatrix}0&-1\\1&0\end{pmatrix}$. You can check $A^2=-I$ (the unit matrix) and that $\mathbf R[A]$ is isomorphic to the field $\mathbf C$ – or $\mathbf Q[A]$ isomorphic to $\mathbf Q(i)$.
For $B$ take, say, $\;\begin{pmatrix}0&1\\0&0\end{pmatrix}$. You can check $\;B^2=0$, so, for any field, $k[B]$ is certainly not an integral domain, since $B$ is nilpotent, with index of nilpotency $2$. More generally, in dimension $n$, take the $n\times n$ matrix such that $b_{ij}=1$ if $j-i=1,\enspace 0$ otherwise. This matrix is nilpotent, with index of nilpotency $n$.