There is an answer to that in the syllabus:
Citing is as simple as pasting a Stack Overflow link into a // comment right above the cited code!
I have responded in the wrong location, whoops
I would say put a comment in the code acknowledging where you found it and who wrote it (if you can find that).
Yes, include a link if it was from an online source. If it was a person who helped, give credit to them using their full name.