Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
22 views3 pages

C

C++

Uploaded by

Mayank Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

C

C++

Uploaded by

Mayank Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

What will be the output of the following cout << *ptr << endl;
code? *ptr = 10;
#include <iostream> cout << x << endl;
using namespace std; return 0;
void swap(int &a, int &b) }
{ A) 5, 10
int temp = a; B) 10, 10
a = b; C) 5, 5
b = temp; D) 10, 5
}
int main() 4. What is the output of the following code
{ snippet?
int x = 5, y = 10; #include <iostream>
swap(x, y); using namespace std;
cout << “x: ” << x << “, y: ” << y << endl; int main() {
return 0; int i = 0;
} for (; i < 5; ++i) {
A) x: 5, y: 10 if (i == 3)
B) x: 10, y: 5 break;
C) x: 0, y: 0 }
D) Compilation Error cout << i << endl;
2.What is the output of the code snippet return 0;
below? }
#include <iostream> A) 3
using namespace std; B) 4
class A { C) 5
public: D) Compilation Error
virtual void show() { 5. What will be the output of the following
cout << “Class A” << endl; code snippet?
} #include <iostream>
}; using namespace std;
class B : public A { int main() {
public: int arr[] = {1, 2, 3, 4, 5};
void show() { int *ptr = arr;
cout << “Class B” << endl; cout << ptr[3] << endl;
} return 0;
}; }
int main() { A) 1
A *ptr = new B(); B) 2
ptr->show(); C) 3
return 0; D) 4
} 6. What will be the output of the following
A) Class A code snippet?
B) Class B #include <iostream>
C) Compilation Error using namespace std;
D) Undefined Behavior class Base {
public:
Base() {
cout << “Base Constructor” << endl;
}
~Base() {
cout << “Base Destructor” << endl;
3.What does the following code snippet }
output? };
#include <iostream> int main() {
using namespace std; Base* ptr = new Base();
int main() delete ptr;
{ return 0;
int x = 5; }
int *ptr = &x; A) Base Constructor
B) Base Destructor (A) 5020--5020--
C) Base Constructor, Base Destructor (B) 5020--7012020--12020--
D) Base Destructor, Base Constructor (C) 5020--70120200--5020
7. What is the output of the following code (D) 5020--7050200--5020-
snippet? 10.What does the following code snippet
#include <iostream>
output?
using namespace std;
void modifyArray(int arr[]) {
arr[0] = 10; #include<iostream>
}
int main() { int main()
int arr[] = {1, 2, 3, 4, 5}; {
modifyArray(arr); int i=0;
cout << arr[0] << endl; lbl:
return 0; std::cout<<"CppBuzz.com";
} i++;
A) 1 if(i<5)
B) 2 {
C) 3 goto lbl;
D) 10
}
8. What is the output of the following code
snippet?
include <iostream> return 0;
int main()
{ }
if(0) (A) Error
{ (B) 5 times
std::cout<<"Hi"; (C) 4 times
} (D) 6 times
else
{ 11.What does the following code snippet
std::cout<<"Bye"; output?
} include<iostream>
return 0;
} int main()
{
const int a=10;
9.What does the following code snippet a++;
output? std::cout<<a;
#include<iostream> return 0;

void Execute(int &x, int y = 200) }


{ (A) 10
int TEMP = x + y; (B) 11
x+= TEMP; (C) Compilation Error
if(y!=200) (D) Linking Error
std::cout<<TEMP<<x<<y<<"--"; 11.What does the following code output?
} #include<iostream>
class base
{
int main()
public:
{
base()
int A=50, B=20; {
std::cout<<A<<B<<"--"; cout<<"BCon";
Execute(A,B); }
std::cout<<A<<B<<"--"; ~base()
return 0; {
} cout<<"BDest ";
}
};
class derived: public base
{
public:
derived()
{ cout<<"DCon ";
}
~derived()
{ cout<<"DDest ";
}
};
12.What does the following code output?

int main()
{
derived object;
return 0;
}
(A) Dcon DDest
(B) Dcon DDest BCon BDest
(C) BCon DCon DDest BDest
(D) BCon DCon BDes DDest

You might also like