  The measurement of the azimuthal-correlation function of prompt D mesons with
charged particles in pp collisions at $\sqrt{s}$ = 5.02 TeV and p-Pb collisions
at $\sqrt{s_{\rm NN}}$ = 5.02 TeV with the ALICE detector at the LHC is
reported. The D$^{\rm 0}$, D$^{\rm +}$, and D$^{\rm *+}$ mesons, together with
their charge conjugates, were reconstructed at midrapidity in the transverse
momentum interval 3 < $p_{\rm T}$ < 24 GeV/c and correlated with charged
particles having $p_{\rm T}$ > 0.3 GeV/c and pseudorapidity $|\eta| <$ 0.8. The
properties of the correlation peaks appearing in the near- and away-side
regions (for $\Delta \varphi \approx$ 0 and $\Delta \varphi \approx \pi$,
respectively) were extracted via a fit to the azimuthal correlation functions.
The shape of the correlation functions and the near- and away-side peak
features are found to be consistent in pp and p-Pb collisions, showing no
modifications due to nuclear effects within uncertainties. The results are
compared with predictions from Monte Carlo simulations performed with the
PYTHIA, POWHEG+PYTHIA, HERWIG, and EPOS 3 event generators.
