Skip to content

Every context where static appears

Question

List the places the static keyword can be used in C++ and what it means in each.

Short answer

Four main uses. A static local variable keeps its value between calls and is initialised once. At namespace or file scope, static gives a variable or function internal linkage (visible only in that translation unit). A static data member is shared by all objects of the class. A static member function has no this and can be called without an object.

Adapted from Joshi, Denson & Downes, Quant Job Interview Questions and Answers, Q7.32, p.233; question and answer rewritten by SelfMadeQuant.com.

See the hint and the full worked solution in the question bank (free account).

Open the worked solution

Lessons behind this question