A study of the associated production of a Z boson and a charm quark jet (Z + c), and a comparison to production with a b quark jet (Z + b), in pp collisions at a centre-of-mass energy of 8 TeV are presented. The analysis uses a data sample corresponding to an integrated luminosity of 19.7 fb(-1), collected with the CMS detector at the CERN LHC. The Z boson candidates are identified through their decays into pairs of electrons or muons. Jets originating from heavy flavour quarks are identified using semileptonic decays of c or b flavoured hadrons and hadronic decays of charm hadrons. The measurements are performed in the kinematic region with two leptons with pT(l) > 20 GeV, vertical bar eta(l)vertical bar < 2.1, 71 < m(ll) < 111 GeV, and heavy flavour jets with p(T)(jet) > 25 GeV and vertical bar eta(jet)vertical bar < 2.5. The Z + c production cross section is measured to be sigma(pp -> Z + c + X) B(Z -> l(+)l(-)) = 8.8 +/- 0.5 (stat)+/- 0.6 (syst) pb. The ratio of the Z+c and Z+b production cross sections is measured to be sigma(pp -> Z+c+X)/sigma (pp -> Z+b+X) = 2.0 +/- 0.2 (stat)+/- 0.2 (syst). The Z+c production cross section and the cross section ratio are also measured as a function of the transverse momentum of theZ boson and of the heavy flavour jet. The measurements are compared with theoretical predictions.