O GoConqr está de visual novo! Conte para nós o que você achou.

Quiz

Operator Overloading

PathaPadha Support 11 perguntas

Fazer o quiz

Este quiz tem tempo limite, por isso abre no player de sempre.

Perguntas do quiz (11)

  1. 1How can we restrict dynamic allocation of objects of a class using new?
    1. ABy overloading new operator
    2. BBy making an empty private new operator.
    3. CBy making an empty private new and new[] operators
    4. DBy overloading new operator and new[] operators
  2. 2Which of the following operators cannot be overloaded
    1. A(Member Access or Dot operator)
    2. B?: (Ternary or Conditional Operator )
    3. C:: (Scope Resolution Operator)
    4. D* (Pointer-to-member Operator )
    5. EAll of the above
  3. 3Which of the following operators are overloaded by default by the compiler in every user defined classes even if user has not written?
    1) Comparison Operator ( == )
    2) Assignment Operator ( = )
    1. ABoth 1 and 2
    2. Bonly 1
    3. Conly 2
    4. Dnone of the two
  4. 4Which of the following operators should be preferred to overload as a global function rather than a member method
    1. APrefix++
    2. BComparison Operator
    3. CPostfix ++
    4. DInsertion Operator <<
  5. 5How does C++ compiler differs between overloaded postfix and prefix operators?
    1. AC++ doesn't allow both operators to be overlaoded in a class
    2. BA postfix ++ has a dummy parameter
    3. CA prefix ++ has a dummy parameter
    4. DBy making prefix ++ as a global function and postfix as a member function.
  6. 6Predict the output
    #include<iostream>
    using namespace std;
    class A
    {
    int i;
    public:
    A(int ii = 0) : i(ii) {}
    void show() { cout << i << endl; }
    };

    class B
    {
    int x;
    public:
    B(int xx) : x(xx) {}
    operator A() const { return A(x); }
    };

    void g(A a)
    {
    a.show();
    }

    int main()
    {
    B b(10);
    g(b);
    g(20);
    return 0;
    }
    1. ACompiler Error
    2. B10
      20
    3. C10
      10
    4. D20
      20
  7. 7Output of following program?
    #include <iostream>
    using namespace std;
    class Test2
    {
    int y;
    };

    class Test
    {
    int x;
    Test2 t2;
    public:
    operator Test2 () { return t2; }
    operator int () { return x; }
    };

    void fun ( int x) { cout << "fun(int) called"; }
    void fun ( Test2 t ) { cout << "fun(Test 2) called"; }

    int main()
    {
    Test t;
    fun(t);
    return 0;
    }
    1. Afun(int) called
    2. Bfun(Test 2) called
    3. CCompiler Error: Ambiguous call to fun()
  8. 8Predict the output?
    #include<stdlib.h>
    #include<stdio.h>
    #include<iostream>

    using namespace std;

    class Test {
    int x;
    public:
    void* operator new(size_t size);
    void operator delete(void*);
    Test(int i) {
    x = i;
    cout << "Constructor called n";
    }
    ~Test() { cout << "Destructor called n"; }
    };


    void* Test::operator new(size_t size)
    {
    void *storage = malloc(size);
    cout << "new called n";
    return storage;
    }

    void Test::operator delete(void *p )
    {
    cout<<"delete called n";
    free(p);
    }

    int main()
    {
    Test *m = new Test(5);
    delete m;
    return 0;
    }
    1. Anew called
      Constructor called
      delete called
      Destructor called
    2. Bnew called
      Constructor called
      Destructor called
      delete called
    3. CConstructor called
      new called
      Destructor called
      delete called
    4. DConstructor called
      new called
      delete called
      Destructor called
  9. 9#include<iostream>
    using namespace std;

    class Point {
    private:
    int x, y;
    public:
    Point() : x(0), y(0) { }
    Point& operator()(int dx, int dy);
    void show() {cout << "x = " << x << ", y = " << y; }
    };

    Point& Point::operator()(int dx, int dy)
    {
    x = dx;
    y = dy;
    return *this;
    }

    int main()
    {
    Point pt;
    pt(3, 2);
    pt.show();
    return 0;
    }
    1. Ax = 3, y = 2
    2. BCompiler Error
    3. Cx = 2, y = 3
  10. 10Which of the following operator functions cannot be global, i.e., must be a member function
    1. Anew
    2. Bdelete
    3. Cconversion operator
    4. Dall the above

Informações

Descrição
C++ Quiz sobre Operator Overloading, criado por PathaPadha Support em 28-10-2020.
Idioma
English
Visualizações
91
Etiquetas
c++
Avaliação
Ainda sem avaliações
Avalie este quiz
Avalie este quiz

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?