Ilp C++ Final Quiz

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Srikanth_kanthet
S
Srikanth_kanthet
Community Contributor
Quizzes Created: 5 | Total Attempts: 905
| Attempts: 300 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1. A special library function which is called automatically when no handler at any level catches the       exception

Explanation

The terminate() function is a special library function that is called automatically when no exception handler at any level catches the exception. It is responsible for terminating the program and cleaning up any resources that were allocated.

Submit
Please wait...
About This Quiz
Ilp C++ Final Quiz - Quiz

The ILP C++ Final Quiz assesses advanced understanding of C++ programming concepts including virtual functions, exception handling, operator overloading, and memory management. This quiz is designed to challenge learners on key aspects of C++ and object-oriented programming.

Tell us your name to personalize your report, certificate & get on the leaderboard!
2.           int main()           {             int a=2,b=3;             if ((a==2) || (b++==4))             cout<<"success";             return 0;           }           What will be the values of a and b ?

Explanation

The values of a and b will be 2 and 3 respectively. In the if statement, the first condition (a==2) is true, so the second condition (b++==4) is not evaluated. Therefore, the value of b remains unchanged. Since the if statement is true, the statement "success" is printed.

Submit
3. Class VirtualClass {          int x,y;          public:          VirtualClass() {  x=1,y=2; }          virtual void operator<<(ostream&); }; // end of class          void VirtualClass::operator<<(ostream &os)          {  os<<this->x<<"\t"<<this->y;   }         int main() {                     VirtualClass vcObj;                     vcObj<<cout;                     return 0; }

Explanation

The code defines a class called VirtualClass with two integer variables x and y. The constructor initializes x to 1 and y to 2. The class also overloads the

Submit
4. What is the output of the following code      int main() {           char s1[20]="Hello";           char s2[20]="Hai";           s2=s1;           cout<<"String1 : "<<s1;           cout<<"  String2 : "<<s2;           return 0;                                   }

Explanation

The given code tries to assign one array to another, which is not allowed in C++. This results in a compilation error stating "forbidden assignment of arrays". Arrays cannot be assigned directly to each other in C++, instead, you need to use functions like strcpy or strncpy to copy the contents of one array to another.

Submit
5. What is the output of the below code   int main(){ int i=0; for(i=0;i<20;i++)  switch(i) {     case 0:i+=5;     case 1:i+=2;     case 5:i+=5;     default: i+=4;    }  cout<<i;  return 0;  }

Explanation

The code starts with initializing the variable i to 0. Then, it enters a for loop with the condition i
When i is 0, it adds 5 to i and continues to the next case.
When i is 1, it adds 2 to i and continues to the next case.
When i is 5, it adds 5 to i and continues to the next case.
If none of the above cases match, it goes to the default case and adds 4 to i.

After the switch statement, the value of i is printed using cout.

In this code, the loop runs until i becomes 20. The switch statement modifies the value of i based on the cases.

The final value of i is 22, which is the output of the code.

Submit
6. What is the output of the following code class base{    public : virtual void func1()=0;            void func2() {               cout<<"\n In base, function2";  }  }; //end of class class derived : public base{    public :        void fun3()  {               cout<<"\n In derived , function3"; } };//end of class int main(){     derived d;     d.fun3();     return 0;  }

Explanation

The code will result in a compilation error because the derived class is not implementing the pure virtual function func1() from the base class. Since func1() is declared as a pure virtual function in the base class, it must be implemented in any derived class that inherits from the base class. Since the derived class does not implement func1(), the code will not compile.

Submit
7. What is the output of the following code class base{    public : virtual void display()                        {  cout<<" \n I am in base-display ";}                        void virtual show()             {  cout<<" \n I am in base-show ";             }             virtual void show1(){cout<<"In base show1 ";} }; class derived : public base {}; int main(){  derived d;  cout<<sizeof(d)<<"\n";}

Explanation

The output of the code is 8. This is because the sizeof operator is used to determine the size of an object or data type in bytes. In this case, the object "d" is of type "derived", which is derived from the base class. Since the derived class does not have any additional member variables or functions, its size is the same as the base class, which is 8 bytes.

Submit
8.  class Test{  public:          ~Test() {                  cout<<" Destructor"; } };   //end of class  int main() {          Test t;          t.~Test();          return 0;  }

Explanation

The given code snippet creates an object of the Test class named "t" in the main function. Then, the destructor of the Test class is explicitly called using the syntax "t.~Test();". This results in the destructor being called twice, leading to the output "Destructor Destructor". Therefore, the correct answer is "Destructor Destructor".

Submit
9. What is the output of the following code int main(){    int i=4,j;    j=i<<2;    cout<<j;    return 0;}

Explanation

The code assigns the value 4 to the variable i. Then, it performs a left shift operation on i by 2 bits, resulting in 16. Finally, it prints the value of j, which is 16.

Submit
10. #define SQR(x) (x*x)    main()    {         int a,b=3;         a=SQR(b+2);         cout<<a;         return 0;     }

Explanation

The correct answer is 11.

In the given code, the macro SQR(x) is defined as (x*x).

In the main function, the value of b is 3.

The expression a=SQR(b+2) is evaluated as a=(b+2)*(b+2), which becomes a=3+2*3+2, which simplifies to a=11.

Therefore, the value of a is 11, which is outputted by the cout statement.

Submit
View My Results

Quiz Review Timeline (Updated): Feb 17, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Feb 17, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 12, 2012
    Quiz Created by
    Srikanth_kanthet
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
A special library function which is called automatically when no...
          int main()...
Class VirtualClass {...
What is the output of the following code...
What is the output of the below code...
What is the output of the following code...
What is the output of the following code...
 class Test{...
What is the output of the following code...
#define SQR(x) (x*x)...
Alert!

Advertisement