C-Plus-Plus Questions

0 votes, 0 avg
231

C-Plus-Plus Questions

1 / 15

1. How structures and classes in C++ differ?

2 / 15

2. Consider the following given program and choose the most appropriate output from the given options:

#include   
using namespace std;   
class Base {   
public:   
    Base()     
    { cout<<"Constructing Base n"; }   
    ~Base()   
    { cout<<"Destructing Base n"; }     
};   
class Derived: public Base {   
public:   
    Derived()      
    { cout<<"Constructing Derived n"; }   
    ~Derived()   
    { cout<<"Destructing Derived n"; }   
};   
   
int main(void)   
{   
    Derived *d = new Derived();   
    Base *b = d;   
    delete b;   
    return 0;   
}  

3 / 15

3. What will be the output of the following C++ code?

#include 
    using namespace std;
    int main()
    {
        int a = 5;
        float b;
        cout << sizeof(++a + b);
        cout << a;
        return 0;
    }

4 / 15

4. What did we call an array of the one-dimensional array?

5 / 15

5. What is the output of the given program?

#include < stdio.h >  
using namespace std;  
int main()  
{  
int array[] = {10, 20, 30};  
cout << -2[array];  
return 0;  
}  

6 / 15

6. What will be the output of the following C++ code?

        #include 

        using namespace std;

        int main()

        {

            int a, b;

            int* c;

            c = &a;

            a = 200;

            b = 200;

            *c = 100;

            b = *c;

            cout << *c << " " << b;

            return 0;

        }

7 / 15

7. What is dangling pointer?

8 / 15

8. What is the output of this C++ program in the “test.txt” file?

        #include 

        using namespace std;

        int main ()

        {

            long pos;

            ofstream outfile;

            outfile.open ("test.txt");

            outfile.write ("This is an apple",16);

            pos = outfile.tellp();

            outfile.seekp (pos - 7);

            outfile.write (" sam", 4);

            outfile.close();

            return 0;

        }

9 / 15

9. Pick the incorrect statement about inline functions in C++?

10 / 15

10. Which of the following statements is correct about the formal parameters in C++?

11 / 15

11. What is the difference between delete and delete[] in C++?

12 / 15

12. What is the use of the indentation in c++?

13 / 15

13. Which of the following loops is best when we know the number of iterations?

14 / 15

14. What is do-while loop also known as?

15 / 15

15. What will be the output of the following C++ code?

#include 
using namespace std; 
template 
T max (T &a, T &b)
{
	cout << "Template Called ";
    return (a > b)? a : b;
}
 
template <>
int max  (int &a, int &b)
{
    cout << "Called ";
    return (a > b)? a : b;
}
 
int main ()
{
    int a = 10, b = 20;
    cout << max  (a, b);
}

Your score is

The average score is 32%

0%

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top