I want to know that what is static block in c or c++ with an example? I know what is static but what is the difference between static and static block?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Another alternative is that you might be looking for the analogy of a static
block in Java. A block of code that is run when the application is loaded.
There is no such thing in C++ but it can be faked by using the constructor of a
static object.
HOWEVER. I’ve been bitten by this before as it’s a subtle edge case of the C++
standard. If the static object is not reachable by any code called by main the
constructor of the static object may or may not be called.
I found that with gcc hello will get output and with visual studio it will
not.