Why is Magic Numbers bad ?, and what is the alternative ?
The rest I can understand.
Okay, consider this pseudo-C code to print out Pythagorean Triples:
for(x=1; x < 30; x++)
for(y=x; y < 30; y++)
if(!fractional(sqrt(x*x + y*y)))
printf("%d, %d, %dn", x, y, (int)sqrt(x*x+y*y));
In this case the instances of "30" are a magic number which indicates how far the search will go. The fact that I had to repeat it indicates why it is bad – if I want to search up to 50 or 1000, I now have to edit two places in the code.
If I first say "const int searchLimit = 30;" and refer to this constant in the loop definitions, then I only have to change one place when the problem parameters change.
In C, magic numbers also frequently pop up as a way to simplify memory management, particularly with string handling which is particularly awkward in this language. You allocate a buffer of a fixed length and then - ideally - supply that length to the string functions so that they don't overflow that buffer. If you get the magic numbers mismatched in that case, the result is often a security bug of one kind or another.
The key to knowledge is not to rely on people to teach you it.