The question of who is the "rightful" king depends entirely on the political doctrine of the country in which it happens.
I mean think about it this way: if JFK's wife had a baby six months after he was assassinated, would the baby become President? Obviously not, because American political doctrine explicitly accounts for who becomes President if the current President dies in office.
That being said, it sounds like we're talking about a stereotypical European monarchy, probably post-Magna Carta. In that case you're talking succession via primogeniture. Do we have any examples of a similar situation happening in a European monarchy? Well, history is rich and varied, so indeed we do!
Turns out that in France in 1316, something similar happened. Old King Louis the Quarreler was on his deathbed, but his wife was pregnant. He made some contigency plans, which involved his brother being regent for the baby, should it turn out to be a boy. The king passed, the regent took over, in a few months the baby was born and died five days later, and the regent didn't have to move out of his comfy chair.
Now, this was slightly different than your case - the old King had made arrangements for his brother to take over the regency. In your hypothetical situation, it sounds like the old King either didn't know about the pregnancy, or was somehow unable to make arrangements for it.
These things depend on the actual laws of your kingdom, and more specifically they depend on the concrete wording of the laws. Further, and this might be something they've worked out for other forms of inheritance, it also depends on whether or not your country considers the infant a person at the time of the king's death.
In that case there's three different scenarios:
If the law is written such that the crown transfers immediately upon the death of the previous King, and at that point it transfers to the next heir as defined by primogeniture, and the law does not consider a baby in the womb to be a person for the purposes of inheritance, then the "true king" is the brother B.
On the other hand, if the law considers the baby in the womb to be a person for the purposes of inheritance, then the "true king" is the child (even if he is otherwise indisposed at the beginning of his reign, what with the gestating and all). If he turns out to be a she, then whoops! She wasn't ever King, it was the brother B all along.
On the third hand, if the law is written such that the crown always belongs to the heir of the previous King (which is easy to do with sloppy writing), and the law does not consider a baby in the womb to be a person, then the "true king" is B until the baby is born, at which point the crown transfers to the baby.
So at this point, the question becomes: what are the laws and political doctrines of your country? That'll tell you who the legally-determined "true king" is. If you have some sort of magic that rides on the legal definition of the true king, this might even matter.
But like all the other answers have said, the real mark of a king is keeping your butt on the throne. Whoever manages to do that, by hook or by crook, is the "true" king.