Good to know

C Is Unforgiving

C will do precisely what you tell it, and instead of complaining when something doesn’t make sense it will still try to keep working. This can not only break your program but cause problems to your entire system!

While this sounds dramatic, it usually isn’t. You aren’t going to break your computer. You might end up with some weird bugs though. Take this example:

Sample C Code

This piece of code prints questions to the console, before scanning what the user inputs and storing them as integers. The program is designed to add them together and subtract them before printing the answers back to the user.

You might already see that there is a problem here. The output certainly makes no sense!

Sample Output code giving the wrong answer

Since we never actually subtract the values, the subtracted variable has a nonsense value given to it on initialization. Other programming languages might warn you that you never gave the subtracted variable a value. Not C.

This example is easy to debug visually, but some code is thousands of lines long and incredibly complex, and C won’t help you find what is wrong. Instead, C gives you a stupid answer and no way to find out why. Or is there?

Leave a Reply

Your email address will not be published. Required fields are marked *