Professor Murray added: “It is an open question whether adultery continues to be viable as criminal law even though it remains on the books in 24 states and territories. Nobody is going to be going to jail for it. But it is used in divorce and custody cases and even in some employment cases.”

A number of law professors, including Joanna L. Grossman of Hofstra University, said one reason that adultery laws remain on the books is that getting rid of them would require politicians to declare their opposition to them, something few would do. In addition, many like the idea of the criminal code serving as a kind of moral guide even if certain laws are almost never applied.

Mr. Petraeus is a retired four-star general who collects a military pension and remains subject to military codes of conduct that prohibit adultery. But Diane H. Mazur, a professor of law at the University of Florida and a former Air Force officer, said that the chances of the Army’s calling Mr. Petraeus back to active service in order to court-martial him over adultery are zero, as are any chances of state criminal charges’ being brought.

“That would be reserved for the most unimaginably serious circumstances,” Professor Mazur said. Even within the military code, she added, adultery is charged as a criminal offense only when “the conduct of the accused was to the prejudice of good order and discipline in the armed forces,” she read from the manual for courts-martial. That meant something larger than seemed at stake here.

Professor Murray said her research had led her to conclude that laws regulating sex emanated from a notion that sex should occur only within marriage. Criminal law, she said, was there to reinforce marriage as the legal locus for sex. So any other circumstance — sex in public or with a member of the same sex, or adultery — was a violation of marriage. “Now we live in an age when sex is not limited to marriage and laws are slowly responding to that,” she said. “But we still love marriage. Nobody is going to say adultery is O.K.”