Tip of the week#2: Initialize all the data variables

Whenever you declare a local variable, it is not initialized to any value. It contains a garbage value.

Garbage value is never useful. It is just an uninitialized data. Presence of garbage value might introduce some bugs into your program.

Hence whenever we declare a local variable, the best practice is to initialize it at the same time. Instead of writing “int variable1”, we can write “int variable1 = 0”. This will eliminate the risk of the program code giving unwanted output.

You may also like...

1 Response

  1. Amar sarma says:

    Wow! Great tip guys. Thanks. Lots of appreciation from me.- amar sarwa, guwahati, assam, india

Leave a Reply

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

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet