Cacophony, as a literary device, refers to the use of words with sharp, harsh, and unmelodious sounds to picture the situation the author has described.
A great example is in Gulliver’s Travels, by Jonathan Swift:
“And being no stranger to the art of war, I have him a description of cannons, culverins, muskets, carabines, pistols, bullets, powder, swords, bayonets, battles, sieges, retreats, attacks, undermines, countermines, bombardments, sea-fights …”
The sharp sounds of “c” and “k” give a certain ruggedness to words like “cannons” and “muskets”. The letters “p” and “b” also give words like “pistols” and “bombardments” a powerful oomph behind them. They allow the reader to picture the unpleasantness the author is describing.