+91 90691 39140 | +1 253 214 3115 | info@hub4tech.com | hub4tech

C++ Static Data Interview Questions and Answers

1
What is static class data?

Static data members of a class are declared by preceding the member variable’s declaration with the keyword static. Only one copy of static data members exist and all objects of the class share that variable. Unlike regular data members, individual copies of a static member variable are not made for each object. How many ever no of objects of a class are created, only one copy of static data member is shared amongst all of them. All static variables are initialized to zero before the first object is created.

When a member variable is declared static within a class, it is not defined (ie storage is not allocated for it) We must provide a global definition for it outside the class. This is done by redeclaring the static variable using scope resolution operator (‘::’) to identify the class it belongs to. This causes storage for the class to be allocated.

2
Can you please explain what is class using C++?

A class holds the data and functions that operate on the data. It serves as the template of an object.

3
Uses of static class data
  1. To provide access control mechanism to some shared resource used by all the objects of a class
  2. To keep track of no of objects in existence of a particular class
4
What is static variable?

Static variables are the variables which has exactly one copy per class. They belong to the class as a whole but not for its instances (objects). All static variables are declared by using the modifier ‘static’.

5
What are static and dynamic type checking?

Type checking is the operation on which the arguments that can only be applied for.

Static type checking performs the type checking operation before the execution of the program. To perform this operation, the arguments, expressions, variables must be given a data type.

Dynamic type checking performs the type checking operation at the time of the program execution. To perform this operation, the arguments, expressions, variables must be given a data type.

Copyright ©2015 Hub4Tech.com, All Rights Reserved. Hub4Tech™ is registered trademark of Hub4tech Portal Services Pvt. Ltd.
All trademarks and logos appearing on this website are the property of their respective owners.
FOLLOW US