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 arrays in C++

1 Answer

0 votes
#include <bits/stdc++.h> 
   
int main() { 
    std::valarray<double> varr1 = { 2, 3, 5, 4, 7 }; 
    std::valarray<double> varr2 = { 10, 54, 12, 32, 99 }; 
 
    varr1.swap(varr2); 
   
    for (double &n : varr1) { 
        std::cout << n << ", ";
    } 
    
    std::cout << "\n";
    
    for (double &n : varr2) { 
        std::cout << n << ", ";
    } 
}
   
    
    
    
/*
run:
    
10, 54, 12, 32, 99, 
2, 3, 5, 4, 7, 
    
*/

 



answered Jun 14, 2020 by avibootz

Related questions

1 answer 173 views
1 answer 147 views
1 answer 210 views
1 answer 157 views
1 answer 172 views
1 answer 167 views
1 answer 66 views
66 views asked Oct 28, 2024 by avibootz
...