What is the output of the following code in C++?

26 min
Score: 0
Attempted: 0/26
Subscribe
1. What is the output of the following code in C++? (Variables & Arithmetic)
int a=4,b=6; cout<<a*b;




2. What is the output of the following code in C++? (Increment Operator)
int a=5; cout<<a++<<” “<<a;




3. What is the output of the following code in C++? (Pre-increment)
int a=5; cout<<++a;




4. What is the output of the following code in C++? (If-Else)
int a=10; if(a>5) cout<<“Yes”; else cout<<“No”;




5. What is the output of the following code in C++? (For Loop)
for(int i=1;i<=3;i++) cout<<i;




6. What is the output of the following code in C++? (While Loop)
int i=1; while(i<=3){cout<<i;i++;}




7. What is the output of the following code in C++? (Do-While Loop)
int i=3; do{cout<<i;i–;}while(i>0);




8. What is the output of the following code in C++? (Break Statement)
for(int i=1;i<=5;i++){ if(i==3) break; cout<<i; }




9. What is the output of the following code in C++? (Continue Statement)
for(int i=1;i<=5;i++){ if(i==3) continue; cout<<i; }




10. What is the output of the following code in C++? (Ternary Operator)
int a=4; cout<<(a%2==0?”Even”:”Odd”);




11. What is the output of the following code in C++? (Logical Operators)
int a=5; cout<<(a>3 && a<10);




12. What is the output of the following code in C++? (Relational Operators)
cout<<(10!=5);




13. What is the output of the following code in C++? (Switch Statement)
int x=2; switch(x){case 1:cout<<“One”;break; case 2:cout<<“Two”;break; default:cout<<“Other”;}




14. What is the output of the following code in C++? (Array)
int arr[3]={1,2,3}; cout<<arr[1];




15. What is the output of the following code in C++? (String Length)
string s=”C++”; cout<<s.length();




16. What is the output of the following code in C++? (Function Call)
void show(){cout<<“Hello”;} int main(){show();}




17. What is the output of the following code in C++? (Recursion)
int fun(int n){ if(n==0) return 0; return n+fun(n-1);} cout<<fun(3);




18. What is the output of the following code in C++? (Pointer)
int a=10; int *p=&a; cout<<*p;




19. What is the output of the following code in C++? (Reference)
int a=5; int &r=a; r=10; cout<<a;




20. What is the output of the following code in C++? (Dynamic Memory)
int *p=new int(5); cout<<*p;




21. What is the output of the following code in C++? (Class & Object)
class Test{public:int x=10;}; Test t; cout<<t.x;




22. What is the output of the following code in C++? (Constructor)
class A{public:A(){cout<<“A”;}}; A obj;




23. What is the output of the following code in C++? (Destructor)
class A{public:~A(){cout<<“X”;}}; int main(){A obj;}




24. What is the output of the following code in C++? (Inheritance)
class A{public:void show(){cout<<“A”;}}; class B:public A{}; int main(){B obj; obj.show();}




25. What is the output of the following code in C++? (Function Overloading)
void fun(int x){cout<<“Int”;} void fun(double x){cout<<“Double”;} int main(){fun(5);}




26. What is the output of the following code in C++? (Virtual Function)
class A{public:virtual void show(){cout<<“A”;}}; class B:public A{public:void show(){cout<<“B”;}}; int main(){A* ptr; B obj; ptr=&obj; ptr->show();}




1000+ Programming C Plus Plus MCQs

Highly Recommended C++  Important MCQs with Explanation

  1. Which symbol is used to create multiple inheritances?
  2. If a derived class object is created, which constructor is called first?
  3. Which of the following is not a type of constructor?
  4. a ____ is a member function that is automatically called when a class object is __.
  5. What is the output of the following code in C++?
  6. How many times will the following code print?
  7. Which of the following is a procedural language?
  8. Which of the following is not a programming language?
  9. Which of the following is not an example of high-level language?
  10. While declaring pointer variables which operator do we use?
  11. To which does the function pointer point to?
  12. Which of these best describes an array?
  13. Which of the following is a Python Tuple?

Other important MCQs

Data Structure

Which of the following is not the type of queue?
Database

If one attribute is a determinant of the second, which in turn is a determinant of the third, then the relation cannot be
Python
Which of the following is a Python Tuple?

Leave a Reply

Contents Copyrights Reserved By T4Tutorials