C Plus Plus Miscellaneous - Study Mode
[#751] What will be the output of the following C++ code? #include <iostream>
#include <string>
#include <cstdlib>
using namespace std
template<class T>
class A
{
public:
T func(T a, T b){
return a/b
}
}
int main(int argc, char const *argv[])
{
A <char>a1
cout<<a1.func(65,1)<<endl
cout<<a1.func(65.28,1.1)<<endl
return 0
}
Correct Answer
(A) A A
[#752] What will be the output of the following C++ code? #include <iostream>
#include <array>
using namespace std
int main(int argc, char const *argv[])
{
array<int,5> arr = {1,2,3,4,5}
cout<<"Printing Using [] operator: "
for(int i=0
i<5
i++){
cout<<arr[i]<<" "
}
cout<<endl
cout<<"Printing Using at() function: "
for(int i=0
i<5
i++){
cout<<arr.at(i)<<" "
}
cout<<endl
return 0
}
Correct Answer
(B) Printing Using [] operator: 1 2 3 4 5 Printing Using at() function: 1 2 3 4 5
[#753] What will be the output of the following C++ code? #include <iostream>
#include <string>
#include <tuple>
using namespace std
int main()
{
tuple <int, string> tp1
tuple <int, string> tp2
tp1 = make_tuple(0, "Hello")
tp2 = make_tuple(1, "World")
auto tp3 = tuple_cat(tp1, tp2)
cout<<"("<<get<0>(tp3)<<", "<<get<1>(tp3)<<", "<<get<2>(tp3)<<",
"<<get<3>(tp3)<<")"<<endl
return 0
}
Correct Answer
(A) (0, Hello, 1, World)
[#754] What will be the output of the following C++ code if the following arguments are executed on terminal? ===============program.cpp=============
#include <iostream>
using namespace std
int main(int argc, char const *argv[])
{
for(int i=0
i<argc
i++)
cout<<argv[i]<<"
"
}
=======================================
================commands===============
$ g++ program.cpp -o output
$ ./output Hello World
=======================================
Correct Answer
(A) ./output Hello World
[#755] What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
int x = -1
char *ptr
ptr = new char[256]
try
{
if (x < 0)
{
throw x
}
if (ptr == NULL)
{
throw " ptr is NULL "
}
}
catch (...)
{
cout << "Exception occurred: exiting "<< endl
}
return 0
}
Correct Answer
(C) exception occured: exiting