From page 36 of the 2015/16 FIFA Laws of the Game (emphasis mine):
A player is in an offside position if:
- he is nearer to his opponents’ goal line than both the ball and the second-last opponent
In the first example provided in the question, player C is nearer to his opponents' goal line than the second-last opponent, but not the ball when the ball is last touched by a teammate. He is therefore not in an offside position and will not be penalised when he touches the ball.
In the second example provided in the question, in which player C is nearer to his opponents' goal than both the ball and the second-last opponent when the ball is last touched by a teammate (in the image provided by OP, player C is probably still just behind the ball even though I believe this is not what the original question intended). He is therefore in an offside position and will be penalised for interfering with play when he touches the ball.
Contrary to other answers (which since have been deleted), neither the direction that the ball is played nor where the player is standing when he touches the ball have any relevance on whether an offside offence has occurred.