ExamVeda
Login
Home
Object Oriented Programming Using C Plus Plus
?

A static data member is given a value

Answer & Solution
Correct Answer: Option B
Static data members in C++ are special variables associated with a class, not individual objects of that class.
This means there's only one copy of the static member shared by all objects of the class.
Because of this shared nature, you can't initialize them directly within the class declaration like regular member variables.
Instead, you need to give them a value outside the class definition.
This is done typically by providing an initialization outside the class, often in the same header file or a separate source file.
Therefore, the correct answer is that a static data member is given a value outside the class definition.
Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Revathi
Revathi 2 years ago
no- a static member function can be instantiated within a class or outside the class also