Bloomberg LP Interview Question
Software Engineer / DevelopersStatic in C creates object that is not limited by the scope of the function. The object is initialized the 1st time the function executed and then kept in bss/data memory, saving the value to the next time the function executes.
Static variables not defined in a function but outside are visible only to the functions defined in the file where the static variable is defined.
Static in C++ creates an object not linked to a specific instance of the class but shared by all the instances of the classes and it can be accessed even if no object of that class are created as: class::objvar.
static should be initialized before the main() start to be executed.
Static methods are possible but only if used to access static variables as not linked to a specific instance of the class.
static variable cannot be created inside methods for the same reason.
Static in C provides a way to hide names of the variables and functions so that they are only visible in the file.
- jimmyzzxhlh August 18, 2010Static in C++ allows to access variables and call functions in a class without creating an object.