Why is the init function in fifteen not declared as void init(int), since it uses the integer d?


The int variable named d is a global variable. Global variables are variables that are declared outside of any functions. They can be accessed from anywhere in the source code file and that's why we don't need the function init to accept an int as an argument — because we can access d directly inside it.

Usually we use global variables when we need to access a variable from multiple functions as it's the case with the variable d. This is regarded as a better approach than passing the same variable to multiple functions as an argument again and again as we'd make a copy of that variable every time we pass it to a function.

  • thank you again for your help! Sep 17 '14 at 14:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .