Either C or D controllers will likely accept your requested heading, which can be given as a rough compass point, on initial contact. This contact will be after picking up the terminal info on ATIS, when you contact ground. Your preferred direction will be passed up the chain. A class D may tell you something like "cleared for takeoff, Northbound departure approved", in which case I would feel free to turn as soon as I deemed it safe. In a class C scenario, the same thing could happen, but they might vector you around other traffic. In all cases "resume own navigation" will be permission to take your heading.
If you are still on runway heading and feel you have not been given a clearance sending you where you want to go, you may contact tower or departure control, depending on whom you are with, and say something like "Tower, Diamond two-eight bravo, request heading zero six zero" They may respond with an "approved as requested" or "heading zero six zero approved" or they may give you instructions to "fly present heading, I'll call your turn" indicating they are not ready for you to take your heading yet.
The short answer is, you can take your heading when you have been cleared to do so. Understanding when you have been cleared is a matter of becoming familiar with standard phraseology.
Controllers I have worked with, especially at C and D airspaces have been accommodating. Their job is to send pilots where they want to go while keeping aircraft out of each other’s way. They have rolled along with me when I have changed my mind about landing, I can say "I changed my mind, I'd rather depart the pattern to the south" but to be brief I'll say "Cancel landing intention, request south departure." As airspace gets bigger and controllers are busier (which can vary by location and even time of day) brevity becomes increasingly important. To get practice, you can find out when an particular airspace is less busy. Controllers have been known to be chatty when traffic volume is low, and you may even be able to ask questions about preferred phraseology.