I am trying to write a simple program to add 2 vectors and print the output using 2 different functions. The program intends to add vectors of different sizes and return a vector equal to the size of the larger vector. Although I do not have any compilation errors, the program returns without any output.
As a beginner, I'm not able to identify where I am going wrong. I tried avoiding the use of pointers to make it as easy as possible.
Thanks a lot. This worked. I have a couple of doubts though
1. I thought you can initialize a vector and dynamically allot elements to it. Like push back or insert.Does the operator [] dynamically allot elements to a vector if size is not mentioned?
For example if declare a vector a as follows - vector<int> a.
And try to access a[5], will it return a garbage value or a compile error?
2. Why didn't the original program i wrote return a compilation error?
Yes, you can dynamically append elements to a vector with push_back, but using [] doesn't automatically do that. It is only used to access elements that already exist. But you could do it like this: