Below Mechanism shows the mechanism of formation of diazonium ion. Aniline is treated with Nitrosonium ion which is generated in situ by the reaction of Sodium nitrile and strong acid. The resulting benzenediazonium ion on reaction with CuBr yields Bromobenzene and on treatment with CuCN gives Benzonitrile. Mechanism is as folow,