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 p p collisions at a centre-of-mass energy of 8TeV are presented. The analysis uses a data sample corresponding to an integrated luminosity of 19.7fb-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ℓ>20GeV, | ηℓ| < 2.1 , 71<m111GeV, and heavy flavour jets with pTjet>25GeV and | ηjet| < 2.5. The Z + c production cross section is measured to be σ(pp→Z+c+X)B(Z→ℓ+ℓ-)=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 σ(pp→Z+c+X)/σ(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 the Z boson and of the heavy flavour jet. The measurements are compared with theoretical predictions.