れいぞうこ の なか に ケーキ は 3こ ありました.
せんしゅう 、かんじ を 20こ おぼえ ました.
In the above examples, why does こ come after the number? Is it a counter? If yes, at what instances can it be used? If not, please advise how and when it should be used.
The こ is indeed a counter, usually written 個.
It is a general counter for counting objects, much like つ. Your two example sentences provide proof of the generality of 個, since cakes and kanji characters have few common features.
つ is often taught as the "default" counter ("default" meaning that it can be used in practically any situation to make yourself understood). But つ is only used up to 10 objects. For 11 or more objects, 個 could be regarded as the default counter.
It is a counter. Ko is a kind of generic counter.For example if you were counting paper you would use mai（枚）, cars would use（台）, animals in many cases use hiki/piki (匹) or tou（頭）.
There are many cases, so I would recommend you look up counters. ;)
Wish you the best. 頑張ってね。 ラドより