C Plus Plus Miscellaneous - Study Mode
[#936] What will be the output of the following C++ code? #include <iostream>
using namespace std
int array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
void swap(int x, int y)
{
int temp = array[x]
array[x] = array[y]
array[y] = temp
return
}
void printArray(int size)
{
int i
for (i = 0
i < size
i++)
cout << array[i] << " "
cout << endl
return
}
void permute(int k, int size)
{
int i
if (k == 0)
printArray(size)
else
{
for (i = k - 1
i >= 0
i--)
{
swap(i, k - 1)
permute(k - 1, size)
swap(i, k - 1)
}
}
return
}
int main()
{
permute(3, 3)
return 0
}
Correct Answer
(D) All of the mentioned
[#937] What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class A
{
int a
public:
virtual void func() = 0
}
class B: public A
{
public:
void func(){
cout<<"Class B"<<endl
}
}
int main(int argc, char const *argv[])
{
A *a
a->func()
return 0
}
Correct Answer
(C) Segmentation fault
[#938] What will be the output of the following C++ code? #include <iostream>
using namespace std
class MyInterface
{
public:
virtual void Display() = 0
}
class Class1 : public MyInterface
{
public:
void Display()
{
int a = 5
cout << a
}
}
class Class2 : public MyInterface
{
public:
void Display()
{
cout <<" 5" << endl
}
}
int main()
{
Class1 obj1
obj1.Display()
Class2 obj2
obj2.Display()
return 0
}
Correct Answer
(C) 5 5
[#939] What does this template function indicates? ==================
template<class T>
void func(T a)
{
cout<<a
}
==================
Correct Answer
(B) A function taking a single generic parameter and returning nothing
[#940] What will be the output of the following C++ code? #include <iostream>
#include <algorithm>
#include <vector>
using namespace std
bool myfunction (int i, int j)
{
return (i < j)
}
struct myclass {
bool operator() (int i, int j)
{
return (i < j)
}
} myobject
int main ()
{
int myints[] = {10, 9, 8}
vector<int> myvector (myints, myints + 3)
sort (myvector.begin(), myvector.begin() + 2)
sort (myvector.begin() + 1, myvector.end(), myfunction)
sort (myvector.begin(), myvector.end(), myobject)
for (vector<int> :: iterator it = myvector.begin()
it != myvector.end()
++it)
cout << ' ' << *it
return 0
}
Correct Answer
(A) 8 9 10