The production of heavy quarks in pp collisions at the LHC energies provides a reliable test of perturbative QCD calculations. Comparisons of pp and p–Pb measurements of their hadronization products allow us to investigate how cold nuclear matter effects affect the heavy-quark production. We present ALICE measurements of azimuthal correlations of prompt D mesons with charged hadrons in pp collisions at and p–Pb collisions at . We also show the per-event D-meson yields as a function of the charged-particle multiplicity in pp collisions at .