A variable declared as static in a function is initialized once, and retains its value between function calls.
It is saved in Data section,
The default initial value of an uninitialized static variable is zero.
If a function or global variable is declared static, it can only be accessed in that file. IT Limits the scope to that file
In C++
Static member variable have only one copy per class Unlike other member variable which have Unique copies for every Object .We cannot initialize the static class member inside of the class.We cannot even initialize the static variable inside of the header file.
in .cpp we need to initialised it like this :
Static Functions are again independent of objects .
1) A static member function Can't access NON STATIC MEMBERS can only access static member data
2)A static member function cannot be declared virtual, whereas a non-static member functions can be declared as virtual
3) Can't be declared const and volatile too.
Nice post. Really excellent
ReplyDeletec++ interview questions
salesforce interview questions
bootstrap interview questions
spring interview questions and answers for experienced