Skip to content

Tag Archives: C++-Static Keyword

The static keyword is used with a variable to make the memory of the variable static once a static variable is declared its memory can’t… Read More
Static Function: It is a member function that is used to access only static data members. It cannot access non-static data members not even call… Read More
Static Function: It is basically a member function that can be called even when the object of the class is not initialized. These functions are… Read More
C++ allows defining static data members within a class using the static keyword. When a data member is declared as static, then we must keep… Read More
Prerequisite : Static variables , Static Functions Write a program to design a class having static member function named showcount() which has the property of… Read More
Prerequisite: Static variables in C The static keyword has different meanings when used with different types. We can use static keywords with: Static Variables: Variables… Read More
Output of following C++ program? #include <iostream> class Test { public:     void fun(); }; static void Test::fun()    {     std::cout<<"fun() is static\n"; } int main() {… Read More
Prerequisite: Static Keyword in C++ An object becomes static when a static keyword is used in its declaration. Static objects are initialized only once and… Read More
#include<iostream> using namespace std;    class Test { private:     static int count; public:     Test& fun();  };    int Test::count = 0;    Test& Test::fun() {… Read More
Predict the output of following C++ program. #include <iostream> using namespace std;    class A { private:     int x; public:     A(int _x)  {  x =… Read More
Which of the following is true? (A) Static methods cannot be overloaded. (B) Static data members can only be accessed by static methods. (C) Non-static… Read More
#include <iostream> using namespace std;    class Player { private:     int id;     static int next_id; public:     int getID() { return id; }     Player()  {  id… Read More
Predict the output of following C++ program. #include <iostream> using namespace std;    class Test {     static int x; public:     Test() { x++; }     static… Read More
Static keyword is used for almost the same purpose in both C++ and Java. There are some differences though. This post covers similarities and differences… Read More
1) static member functions do not have this pointer. For example following program fails in compilation with error “`this’ is unavailable for static member functions “… Read More