What is the output of this program?
1. #include2. #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 << ' ' << myvector[i]; 14. return 0; 15. }
Answer : Option A
Explanation :
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