Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (fellowroot):

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);

OpenStudy (rsmith6559):

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.

OpenStudy (anonymous):

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

OpenStudy (fellowroot):

so i should do int a=0; instead of just int a; right

OpenStudy (anonymous):

yea. if you didnt, it'd be no biggie.

OpenStudy (fellowroot):

Thanks.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!