1

So, I was trying to make a list of the different types of variables and wanted to confirm if my classification was correct or not.

Three types, I say:

1.Static/Class

2.Instance

3.Global

I understand that global variables are declared outside the class definition but static variables must be declared (not necessarily instantiated) within the class definition. Are there any more important differences between the class and global variables?

6
  • 1
    Where would local "variables" go in your classification? Commented Mar 15, 2015 at 2:46
  • 2
    These terms are too vague. static has a million different meanings. Commented Mar 15, 2015 at 2:46
  • 2
    Among terms that you'd need to investigate to get the full picture, you should look for instance at storage class specifiers. In a complex language spec, it's really a bit hard to think if there's a "three types of variables" kind of thinking to guide by. It just is what it is. Commented Mar 15, 2015 at 2:47
  • Also I think that global variables have static storage, if I recall correctly. Commented Mar 15, 2015 at 2:47
  • 1
    @Grendan There is no such thing as a "member variable", there are "class members". Class members belong to classes, and must be instantiated through the class as a type... they are a property of a variable declared with that class type while not being variables themselves. Think of classes as a schematic for making variables; if you declare a class but never make an instance, no variables (besides statics). You can apply things like private or protected or public to them, but you cannot declare a private local variable. A class instance, declared as a variable, may be local or global. Commented Mar 15, 2015 at 3:48

1 Answer 1

1

A class is not synonymous with a static variable. Any variable can be declared static. Where it's declared will impact what it actually means.

What Does static Mean?

A class really isn't a variable type, it's how you define a new variable type. int is a type of variable, and Foo is a type of variable once you've defined it with the class keyword.

Instance really makes no sense. You have an instance of a variable, (e.g. an instance of an integer) but that's not a variable type.

In the terms of "types of variables", as you're looking at them, I would say there are two types: global and local. Static just has too many meanings to be included in that list.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.