Online Test

:

 

What is the output of this program?

  #include <iostream.h>
    #include <algorithm.h>
    #include <vector.h>
    using namespace std;
    bool myfunction (int i,int j) { return (i<j); }
    int main () 
    {
        int myints[] = {9, 8, 7, 6, 5};
        vector<int> myvector (myints, myints + 5);
        partial_sort (myvector.begin(), myvector.begin() + 3, myvector.end());
        partial_sort (myvector.begin(), myvector.begin() + 2, myvector.end(), 
        myfunction);
        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 <algorithm.h>
    #include <vector.h>
    using namespace std;
    int main ()
    {
        int first[] = {5, 10, 15, 20, 25};
        int second[] = {50, 40, 30, 20, 10};
        vector<int> v(10);      
        vector<int> :: iterator it;
        sort (first, first + 5);   
        sort (second, second + 5); 
        it = set_union (first, first + 5, second, second + 5, v.begin());
        cout << int(it - v.begin());
        return 0;
    }

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 use of RAII in c++ programing?


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


 What is the output of this program?

    #include <iostream.h>
    #include <algorithm.h>
    using namespace std;
    int main () 
    {
        int myints[] = {1, 2, 3};
        sort (myints, myints + 3);
    do 
    {
    } while ( next_permutation(myints, myints + 3) );
        cout << myints[0] << ' ' << myints[1] << ' ' << myints[2] << '\n';
        return 0;
    }

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

#include<iostream.h> 
class TechEpi
{
    int *p; 
    public:
    TechEpi(int xx, char ch)
    {
        p  = new int(); 
        *p = xx + int(ch); 
        cout<< *p;
    }
    ~TechEpi() 
    {
        delete p;
    }
};
int main()
{
   TechEpi objEpi(10, 'B'); 
    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 out of the following program?

#include<iostream.h> 
class EpiBase
{
    public:
    int x, y; 
    public:
    EpiBase(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy; 
    } 
 };
class EpiDerived : public EpiBase
{
    private:
        EpiBase objBase; 
    public:
    EpiDerived(int xx, int yy) : EpiBase(xx), objBase(yy)
    {
        cout << x          << " " 
             << this->x    << " "  
             << EpiBase::x << " "     
             << this->objBase.x ;
    } 
    ~EpiDerived()
    { }
};
int main()
{
   EpiDerived objDev(11, 22); 
    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>
    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 in text files?
#include <stdio.h>
    int main ()
    {
        char buffer[BUFSIZ];
        FILE *p1, *p2;
        p1 = fopen ("myfile.txt", "w");
        p2 = fopen ("myfile2.txt", "a");
        setbuf ( p1 , buffer );
        fputs ("Buffered stream", p1);
        fflush (p1);
        setbuf ( p2 , NULL );
        fputs ("Unbuffered stream", p2);
        fclose (p1);
        fclose (p2);
        return 0;
    }

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 <stdio.h>
    int main ()
    {
        FILE * p;
        long size;
        p = fopen ("test.txt", "rb");
        if (p == NULL) 
            perror ("Error opening file");
        else
        {
            fseek (p, 0, SEEK_END); 
            size = ftell (p);
            fclose (p);
            printf (" %ld\n", size);
        }
        return 0;
    }

What is the output of this program?

    #include <iostream.h>
    #include <vector.h>
    #include <algorithm.h>
    using namespace std;
    void show(const vector<int>& vi)
    {
        for (size_t i = 0; i < vi.size(); ++i)
            cout << vi[i];
        cout << endl;
    }
    int main()
    {
        vector<int> vi;
        vi.push_back(3);
        vi.push_back(5);
        vi.push_back(5);
        sort(vi.begin(), vi.end());
        show(vi);
        while(next_permutation(vi.begin(), vi.end()))
            show(vi);
        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