The first study of charm quark diffusion with respect to the jet axis in heavy ion collisions is presented. The measurement is performed using jets with p(T)(jet) > 60 GeV/c and D-0 mesons with p(T)(D) > 4 GeV/c in lead-lead (Pb-Pb) and proton-proton (pp) collisions at a nucleon-nucleon center-of-mass energy of root s(NN) = 5.02 TeV, recorded by the CMS detector at the LHC. The radial distribution of D-0 mesons with respect to the jet axis is sensitive to the production mechanisms of the meson, as well as to the energy loss and diffusion processes undergone by its parent parton inside the strongly interacting medium produced in Pb-Pb collisions. When compared to Monte Carlo event generators, the radial distribution in pp collisions is found to be well described by PYTHIA, while the slope of the distribution predicted by SHERPA is steeper than that of the data. In Pb-Pb collisions, compared to the pp results, the D-0 meson distribution for 4 < p(T)(D) < 20 GeV/c hints at a larger distance on average with respect to the jet axis, reflecting a diffusion of charm quarks in the medium created in heavy ion collisions. At higher p(T)(D), the Pb-Pb and pp radial distributions are found to be similar.