Interview Question

Engineering Intern Interview

-Richmond, BC


1. static variables?

AnswerAdd Tags

Interview Answers

2 Answers


Variables that have only one copy per class are known as static variables. They are not attached to a particular instance of a class but rather belong to a class as a whole. They are declared by using the static keyword as a modifier. For example: static type varIdentifier; where, the name of the variable is varIdentifier and its data type is specified by type. Static variables that are not explicitly initialized in the code are automatically initialized with a default value. The default value depends on the data type of the variables.

Anonymous on


Specifically, in C, the keyword static has a couple of different meanings: -When used with a global variable, it limits the scope of that variable to the module/file level. Although it is globally available within the module, the variable cannot be accessed from other files/modules with the extern keyword. - When used with a variable within a function, it declares a variable that is initialized at most once. All subsequent accesses to the variable (even through multiple calls of the function) will share a single location in memory, and its value will persist. - When used with a function declaration, it declares the scope of that function to be limited to that module -- this can help prevent function name collisions across multiple linked modules.

Christyn on

Add Answers or Comments

To comment on this, Sign In or Sign Up.