  A density functional theory study of substitutional carbon impurities in ZnO
has been performed, using both the generalized gradient approximation (GGA) and
a hybrid functional (HSE06) as exchange-correlation functional. It is found
that the non-spinpolarized C$_\mathrm{Zn}$ impurity is under almost all
conditions thermodynamically more stable than the C$_\mathrm{O}$ impurity which
has a magnetic moment of $2\mu_{\mathrm{B}}$, with the exception of very O-poor
and C-rich conditions. This explains the experimental difficulties in sample
preparation in order to realize $d^{0}$-ferromagnetism in C-doped ZnO. From GGA
calculations with large 96-atom supercells, we conclude that two
C$_\mathrm{O}$-C$_\mathrm{O}$ impurities in ZnO interact ferromagnetically, but
the interaction is found to be short-ranged and anisotropic, much stronger
within the hexagonal $ab$-plane of wurtzite ZnO than along the c-axis. This
layered ferromagnetism is attributed to the anisotropy of the dispersion of
carbon impurity bands near the Fermi level for C$_{\mathrm{O}}$ impurities in
ZnO. From the calculated results, we derive that a C$_{\mathrm{O}}$
concentration between 2% and 6% should be optimal to achieve
$d^{0}$-ferromagnetism in C-doped ZnO.
