Valency is the combining capacity of an atom.
The atomic number of carbon is 6. Its electronic configuration is (2, 4). It has 4 electrons in its outermost shell (valence shell). Carbon will either gain or lose these 4 electrons to complete its octet. Thus, the valency of carbon is 4.
Similarly, atomic number of chlorine is 17. Its electronic configuration is (2, 8, 7). Thus, chlorine will gain 1 electron to complete its octet. Therefore, the valency of chlorine is 1.