C Plus Plus Miscellaneous - Study Mode

[#651] What will be the output of the following C++ code? #include <iostream>
#include <string>
#include <cstdlib>
using namespace std

template<class T>
class A
{
T a

public:
A(){}
~A(){}
}

int main(int argc, char const *argv[])
{
A <char>a1

A <int>a2

A <double>a3

cout<<sizeof(a1)<<endl

cout<<sizeof(a2)<<endl

cout<<sizeof(a3)<<endl

return 0

}
Correct Answer

(A) 1 4 8

[#652] What will be the output of the following C++ code? #include <iostream>
using namespace std

class Cat
{
public:
int age

int weight

}

int main()
{
Cat f

f.age = 56

cout << "Gates is "

cout << f.age << " years old.
"

}
Correct Answer

(B) Gates is 56 years old

[#653] What will be the output of the following C++ code in the text file? #include <stdio.h>
int main ()
{
FILE * pFile

char c

pFile = fopen("sample.txt", "wt")

for (c = 'A'

c <= 'E'

c++)
{
putc (c, pFile)

}
fclose (pFile)

return 0

}
Correct Answer

(C) ABCDE

[#654] What will be the output of the following C++ code? #include<iostream>
#include <string>
using namespace std

template <class T>
class Print
{
public:
int operator()(T a){
cout<<a<<endl

}
}

int main()
{
Print<string> str

Print<int> integer

int a = 100

string s = "Hello World"

str(s)

integer(a)

return 0

}
Correct Answer

(D) Hello World 100

[#655] What will be the output of the following C++ code? #include <iostream>
#include <deque>
using namespace std

int main ()
{
deque<int> mydeque

int sum (0)

mydeque.push_back ( 10 )

mydeque.push_back ( 20 )

mydeque.push_back ( 30 )

while (!mydeque.empty())
{
sum += mydeque.back()

mydeque.pop_back()

}
cout << sum << '
'

return 0

}
Correct Answer

(D) 60