Online Test

:

 

What is the output of this program?

   #include <iostream.h>
    using namespace std;
    class Base
    {
        public:
        virtual void print() const = 0;
    };
    class DerivedOne : virtual public Base
    {
        public:
        void print() const
        {
            cout << "1";
        }
    };
    class DerivedTwo : virtual public Base
    {
        public:
        void print() const
        {
            cout << "2";
        }
    };
    class Multiple : public DerivedOne, DerivedTwo
    {
        public:
        void print() const
        {
            DerivedTwo::print();
        }
    };
    int main()
    {
        Multiple both;
        DerivedOne one;
        DerivedTwo two;
        Base *array[ 3 ];
        array[ 0 ] = &both;
        array[ 1 ] = &one;
        array[ 2 ] = &two;
        for ( int i = 0; i < 3; i++ )
        array[ i ] -> print();
        return 0;
    }

What is the output of this program?

  #include <stdexcept.h>
    #include <limits.h>
    #include <iostream.h>
    using namespace std;
    void MyFunc(char c)
    {
        if (c < numeric_limits<char>::max())
            return invalid_argument;
    }
    int main()
    {
        try
        {
            MyFunc(256);
        }
        catch(invalid_argument& e)
        {
            cerr << e.what() << endl;
            return -1;
        }
        return 0;
    }

What is the output of this program?

#include <iostream.h>
    using namespace std;
    template 
    type Max(type Var1, type Var2)
    {
        return Var1 > Var2 ? Var1:Var2;
    }
    int main()
    {
        int p;
        p = Max(100, 200);
        cout << p << endl;
        return 0;
    }

What is the output of this program?

#include <iostream.h>
    using namespace std;
    class Foo
    {
        public:
        Foo(int i = 0){ _i = i;}
        void f()
        {
            cout << "Executed"<<endl;
        }
        private:
        int _i;
    };
    int main()
    {
        Foo *p = 0;
        p -> f();
    }

What is the output of this program?

 #include <iostream.h>
    using namespace std;
    struct A 
    {
        virtual void f()  
        { 
            cout << "Class A" << endl; 
        }
    };
    struct B : A 
    {
        virtual void f() 
        { 
            cout << "Class B" << endl;
        }
    };
    struct C : A 
    {
        virtual void f() 
        {
            cout << "Class C" << endl; 
        }
    };
    void f(A* arg) 
    {
        B* bp = dynamic_cast<B*>(arg);
        C* cp = dynamic_cast<C*>(arg);
        if (bp)
            bp -> f();
        else if (cp)
            cp -> f();
        else
            arg -> f();  
    };
    int main() 
    {
        A aobj;
        C cobj;
        A* ap = &cobj;
        A* ap2 = &aobj;
        f(ap);
        f(ap2);
    }

What is the output of this program?

   #include <iostream.h>   
    #include <algorithm.h>  
    using namespace std;
    int main () 
    {
        cout << "max(1, 2) == " << max(1, 2) << '\n';
        cout << "max('a', 'z') == " << max('a', 'z') << '\n';
        return 0;
    }

What is the output of this program?

 #include <iostream.h>
   #include <string.h>
   using namespace std;
   int main ()
   {
       string str ("Ubuntu");
       cout << str.capacity();
       cout << str.max_size();
       return 0;
   }

What will be the output of the following program?

#include <iostream.h>
    #include <cstring.h>
    using namespace std;
    int main ()
    {
        char str1[10] = "Hello";
        char str2[10] = "World";
        char str3[10];
        int  len ;
        strcpy( str3, str1);
        strcat( str1, str2)
        len = strlen(str1);
        cout << len << endl;
        return 0;
    }

What is the output of this program?

  #include <iostream.h>
    #include <algorithm.h>
    using namespace std;
    bool myfn(int i, int j) 
    {
        return i < j;
    }
    int main () 
    {
        int myints[ ] = {3, 7, 2, 5, 6, 4, 9};
        cout <<  *min_element(myints, myints + 7, myfn) << '\n';
        cout << *max_element(myints, myints + 7, myfn) << '\n';
        return 0;
    }

What is the use of RAII in c++ programing?


What is the output of this program?

 #include <iostream.h>
    #include <algorithm.h>
    #include <vector.h>
    using namespace std;
    int main () 
    {
        vector<int> myvector;
        for (int i = 1; i < 6; ++i) 
            myvector.push_back(i);
        reverse(myvector.begin(), myvector.end());
        for (vector<int> :: iterator it = myvector.begin(); it != myvector.end(); ++it)
            cout << ' ' << *it;
        return 0;
    }

What is the output of this program?

   #include <iostream.h>
    #include <typeinfo.h>
    using namespace std;
    class A 
    { 
    };
    int main()
    { 
        char c; float x;
        if (typeid(c) != typeid(x))
        cout << typeid(c).name() << endl;
        cout << typeid(A).name();
        return 0;
    }

 


When our function doesn’t need to return anything means what we will as parameter in function?


Which of the following statement is correct about the program given below?

#include<iostream.h>
long GetNumber(long int Number)
{
    return --Number;
}
float GetNumber(int Number)
{
    return ++Number;
}
int main()
{
    int x = 20;
    int y = 30;
    cout<< GetNumber(x) << " ";
    cout<< GetNumber(y) ;
    return 0; 
}

What is the output of this program?

 #include <iostream.h>
    using namespace std;
    template <class type>
    class Test
    {
        public:
        Test()
        {
        };
        ~Test()
        {  
        };
        type Funct1(type Var1)
        {
            return Var1;
        }
        type Funct2(type Var2)
        {
            return Var2;
        }
    };
    int main()
    {
        Test<int> Var1;
        Test<double> Var2;
        cout << Var1.Funct1(200);
        cout << Var2.Funct2(3.123);
        return 0;
    }
 

About Us

TechEpi.com is an online learning website.We cover the latest tech news,online tutorials,blog,online test for Aptitude,C,Java,PHP to improve your knowledge.

Newsletter


Follow TechEpi on