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 swap two array objects in C++

1 Answer

0 votes
#include <iostream>
#include <array>
 
int main ()
{
  std::array<int, 5> first = {1, 2, 3, 4, 5};
  std::array<int, 5> second = {6, 7, 8, 9, 0};
   
  first.swap(second);
 
  for (int &n : first) std::cout << n << ", ";
  std::cout << '\n';
 
  for (int &n : second) std::cout << n << ", ";
 
  return 0;
}
   
   
   
/*
run:
   
6, 7, 8, 9, 0, 
1, 2, 3, 4, 5, 
    
*/

 



answered Jul 29, 2020 by avibootz
edited Jul 29, 2020 by avibootz

Related questions

1 answer 94 views
94 views asked Apr 19, 2023 by avibootz
1 answer 157 views
1 answer 66 views
66 views asked Oct 28, 2024 by avibootz
1 answer 114 views
1 answer 124 views
1 answer 117 views
2 answers 158 views
...