0

I have learned that those global variables that will not be used outside the file should be made non-global variable by appending static keyword like static int a;

I want to know that why we should do this?

2
  • You can't accidentally use it in another file. Commented Dec 27, 2019 at 11:41
  • @user253751 So for only this purpose, we make non-global variables? Commented Dec 27, 2019 at 12:17

1 Answer 1

0

Static implies a translation unit level scope only.

However, you don't need to make it non-global + static.

You can very well make it global static to curb the scope to translation unit level.

Sign up to request clarification or add additional context in comments.

1 Comment

Translation unit* scope. Not file scope.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.