C Plus Plus Miscellaneous - Study Mode

[#941] Which of the following is the correct syntax of using pair p?
Correct Answer

(A) pair <type,type> p

[#942] What will be the output of the following C++ code? #include <stdio.h>
int main ()
{
int n
FILE * p
char buffer [5]
p = fopen ("myfile.txt", "w+")
for ( n = 'A'
n <= 'D'
n++)
fputc ( n, p)
rewind (p)
fread (buffer, 1, 5, p)
fclose (p)
buffer[3] = 'x00'
puts (buffer)
return 0
}
Correct Answer

(B) ABC

[#943] What will be the capacity of vector at the end in the following C++ code? #include <iostream>
#include <vector>

using namespace std
int main()
{
vector<int> v
for (int i = 1
i <= 5
i++)
v.push_back(i)
v.reserve(50)
cout<<v.capacity()
return 0
}
Correct Answer

(C) 50

[#944] What will be the output of the following C++ code? #include <iostream>
#include <deque>
using namespace std
int main ()
{
unsigned int i
deque<int> a (3,100)
deque<int> b (5,200)
a.swap(b)
cout << "a contains:"
for (deque<int>::iterator it = a.begin()
it != a.end()
++it)
cout << ' ' << *it
cout << "b contains:"
for (deque<int>::iterator it = b.begin()
it != b.end()
++it)
cout << ' ' << *it
return 0
}
Correct Answer

(A) a contains: 200 200 200 200 200b contains: 100 100 100

[#945] What will be the output of the following C++ code? #include <iostream>
#include <bitset>
using namespace std
int main()
{
bitset<8> b1(string("15"))
cout<<b1
}
Correct Answer

(D) Run-time error