Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to pass vector to a function in C++

1 Answer

0 votes
#include <iostream>
#include <vector>

void printVector(const std::vector<int> &v) {

    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i] <<  " ";
    }

}

int main()
{
    std::vector<int> v = {5, 7, 8, 1, 7, 4, 9, 3};
   
    printVector(v);
     
    return 0;
}
   
   
   
   
/*
run:
   
5 7 8 1 7 4 9 3 
   
*/

 



answered Dec 6, 2020 by avibootz

Related questions

1 answer 150 views
3 answers 213 views
2 answers 157 views
157 views asked Feb 11, 2019 by avibootz
1 answer 78 views
78 views asked Dec 19, 2024 by avibootz
2 answers 178 views
178 views asked Feb 12, 2019 by avibootz
4 answers 85 views
...