C programming. If I scanf in some values from a user do I need to do this first int a=0; scanf("%d",&a); or can I just not set it equal to zero like this. int a; scanf("%d",&a);
Many programmers get into the habit of setting a variable's value as soon as it's declared so there's no chance that it has a garbage value. As long as the first thing that is done with a variable is assignment, life is good. The more code between declaration and actual use, the better the chance that this could be forgotten.
yes. Like @rsmith6559 said. you set it, it takes a couple of "bytes" more. if you do not set it, you save a couple of bytes. Program size wise, it dont make no difference
so i should do int a=0; instead of just int a; right
yea. if you didnt, it'd be no biggie.
Thanks.
Join our real-time social learning platform and learn together with your friends!