It depends. In North Carolina child custody is determined by using a standard whereby the judge will determine the best interest of the child.
The judge looks at every relevant factor that has to do with the children i.e. the stability of the parties, the living situation of the parties, who encourages the child in educational endeavors, and every other factor that has to do with the children.
While parties can contract outside of the court as to who has custody of the children, the court always has the opportunity to come in and determine the best interest of the children.