In recursive function, the variable should be declared as local or static or global variable?
Thanks in advance…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends. A static variable means you have one variable that’s shared across all recursive invocations. A normal local variable means each recursive invocation gets its own copy of that variable. You need to choose the one that makes sense for what you’re doing.
A global is like a static local variable (one variable shared by all invocations) but it’s also visible to the rest of the application.