How many d-eletrons are in the outer shell of following compounds:
Sulfur does not have any "d" electrons as you said.

Before losing two electrons from the 4s sublevel, Zinc's outer sublevel is 4s (not 4p as you mentioned).  After those two electrons are lost, the outermost sublevel becomes the 3d sublevel which contains 10 electrons.  

Yes, it does matter whether the atom forms a compound or not, so we can understand where the electrons are allocated/transferred.

Here is the general rule for how to consider electrons in atoms.  Electrons fill up an atom via the Aufbau principle (image attached).  However, after filling, they arrange themselves in the energy according to the their principle quantum number (1, 2, 3,...) and their sublevel type (s, p, d, f).  For example, 4s fills before 3d in zinc, but after filling, 4s gains a higher energy than 3d.