MCQ on Static Members in C++: Multiple Choice Questions on C++ Static Members

MCQ on Static Members in C++ with answers and explanations for placement tests and job interviews. This C++ MCQ on Static Members is useful for the campus placement for all freshers including Engineering Students, MCA students, Computer and IT Engineers, etc.

Our C++ Quiz on static Members focuses on all areas of the C++ static members and its concept. We will regularly update the MCQ on the C++ Static members and most interesting thing is that questions come in a random sequence. So every time you will feel new questions.

You may have come across several C++ courses during your search for learning the C++ language. Our team of experts has carefully analyzed some C++ courses for you. You can check the courses, Trial of some courses is free.

 

Guideline of MCQ on Static Members in C++:

This MCQ on the static members in C++ is intended for checking your knowledge of C++. It takes 30 minutes to pass the C++ quiz on the static member function and data. If you don’t finish the C++ static members quiz within the mentioned time, all the unanswered questions will count as wrong. Every unanswered question will count as wrong. MCQ on static data members and functions in C++ has randomization features that give you a new question set at every attempt.

Here we have also implemented a feature that does not allow the user to see the next question or finish the quiz without attempting the current C++ static member quiz.

1 votes, 5 avg

You have 30 minutes to take the MCQs on static members in C++

Your time has been Over.


Quiz On static members in C+

C++ MCQ

Quiz On static members in C+

1 / 16

Which statement is true for the static member function?

2 / 16

The static member functions __________________

3 / 16

Which is the correct syntax to access the static member functions with the class name?

4 / 16

The static data member _________________

5 / 16

If a static data member is not declared thread_local there is one copy of the data member that is shared by all the objects of the class.

6 / 16

What is the output of the below code?

#include<iostream>
using namespace std;

class X
{
private:
    static int count;
public:
    X& fun();
};

int X::count = 10;

X& X::fun()
{
    X::count++;
    cout << X::count << " ";
    return *this;
}

int main()
{
    X obj;
    obj.fun().fun().fun().fun();
    return 0;
}

 

7 / 16

Which among the following is true?

8 / 16

If static data member are made inline, ______________

9 / 16

What is the output of the below code?

#include <iostream>
using namespace std;

class Y
{
private:
    int m_x;
public:
    Y(int x)
    {
        m_x = x;
    }
    int get()
    {
        return m_x;
    }
};

class X
{
    static Y a;
public:
    static int get()
    {
        return a.get();
    }
};

int main()
{
    X b;

    cout << b.get();

    return 0;
}

 

10 / 16

If a static data member is declared thread_local there is one copy of the member per thread.

11 / 16

Which statement is true for static members?

12 / 16

Which of the following is true?

13 / 16

Predict the output of the below code.

#include <iostream>
using namespace std;

class Y
{
private:
    int id;
    static int next_id;
public:
    int getID()
    {
        return id;
    }
    Y()
    {
        id = next_id++;
    }
};
int Y::next_id = 1;

int main()
{
    Y obj1;
    Y obj2;
    Y obj3;
    cout << obj1.getID() << " ";
    cout << obj2.getID() << " ";
    cout << obj3.getID();
    return 0;
}

14 / 16

What is the output of the below code?

#include <iostream>
using namespace std;

class Y
{
    static int x;
public:
    Y()
    {
        x++;
    }
    static int getX()
    {
        return x;
    }
};

int Y::x = 0;

int main()
{
    cout << Y::getX() << " ";
    Y obj[3];
    cout << Y::getX();
    return 0;
}

 

15 / 16

The output of the below code?

#include <iostream>
class X
{
public:
    void foo();
};
static void X::foo()
{
    std::cout<<"foo() is static function\n";
}

int main()
{
    X::foo();
    return 0;
}

 

 

16 / 16

Are static members obey the class rule?

Your score is

The average score is 0%

0%

Recommended Articles for you: