Last year, nearly 5,000 people were charged in New York City with dealing small quantities of heroin or cocaine, and in 2014, just over 6,000 people faced such charges. But the number of those that involved buy-and-bust cases against addicts is unknown. A vast majority of drug-dealing charges end in plea deals, so there are few trials during which such distinctions might emerge.

The 55-year-old crack addict, Reginald J., agreed to speak to a reporter on the condition that only the first letter of his surname be used when identifying him. In an interview, he articulated one of the issues with these sting operations: It is tough for addicts to say no.

“For him to put the money in my hands, as an addict, let me tell you what happens,” he said. “I like to think I could resist it, but I’m way beyond that. My experience has shown me that 1,000 times out of 1,000 times, I will be defeated.”

At one trial in January, a defendant testified that he had shown an undercover officer track marks on his arm. At another trial, in December, the defendant testified that he had even told an undercover officer about his desire to get clean. “You know what? We got to stop getting high,” the man, Mitchell Coward, testified. “That’s what I told him.”

Joan Vollero, a spokeswoman for the Manhattan district attorney’s office, which prosecuted three of the four cases reviewed by The Times, declined to say whether the office considered such sting operations to be appropriate. But she did say that in some cases, addicts who pleaded guilty to felony drug-dealing charges were steered toward treatment instead of prison.

Law enforcement officials said that sting operations remained a necessary and sensible response to neighborhood complaints about drug dealing and narcotics use. For instance, the McDonald’s on the Lower East Side, where the undercover officer approached the 21-year-old heroin addict, was the topic of dozens of recent community complaints about drug dealing and drug use there or outside its doors, the police said.