Etymology for “Mc‑” and “O’‑” prefix in surnames
Solution 1:
Mc is an abbreviation of Gaelic Mac, "son".
The standard way to form a name using a simple patronymic byname for men is:
<single given name> mac <father's given name (in genitive case & sometimes lenited)>
which means
<given name> son <of father's given name>
For example, Donnchadh who is the son of Fearchar mac Domhnaill would be:
Donnchadh mac Fearchair
which means
Donnchadh son of Fearchar
O' is the Anglicized way to write Ó "male descendant of".
The standard way to form a name using an Irish clan affiliation byname for men is:
<single given name> Ó <eponymous clan ancestor's name (in genitive case)>
which means
<given name> male descendant <of eponymous clan ancestor>
For example, Donnchadh who is the son of Fearchar Ó Conchobhair would be:
Donnchadh Ó Conchobhair
which means
Donnchadh male descendant of Conchobhar
Two common misconceptions are (1) that Mac means "son of" — it actually means just "son", and the "of" comes from putting the father's name into the possessive case; and (2) that Mc is Irish while Mac is Scottish (or vice versa) — actually, Mc and Mac are two ways to write the same thing, and both occur in names from both countries. (What is true is that O' is almost exclusively Irish; despite the romantic notions we have of Scottish clans, they didn't use their clan affiliation in their names.)
Edit: as for why the prefix is used even though the prefix-less names look perfectly fine on their own, this is basically Gaelic grammar and thus out of scope for this site. Suffice it to say, some languages are fine with unmarked patronymics — names that identify the bearer's father using the unmodified given name — but Gaelic is not one of them.
Solution 2:
Mac, is the Gaelic for "son", and O' means "grandson of". It is found mainly in names from family of Irish origin.
See Wikipedia for more information.