Question
1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
vector myvector (5);
7.
int* p = myvector.data();
8.
*p = 10;
9.
++p;
10.
*p = 20;
11.
p[2] = 100;
12.
for (unsigned i = 0; i < myvector.size(); ++i)
13.
cout
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
vector myvector (5);
7.
int* p = myvector.data();
8.
*p = 10;
9.
++p;
10.
*p = 20;
11.
p[2] = 100;
12.
for (unsigned i = 0; i < myvector.size(); ++i)
13.
cout
Answer: Option A
Was this answer helpful ?
In this program, We are allocating the values to the vector and unallocated values are left as zero.
Output:
$ g++ vect4.cpp
$ a.out
10 20 0 100 0
Was this answer helpful ?
More Questions on This Topic :
Question 3.
What do vectors represent?
....
Submit Solution