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,988 questions

51,933 answers

573 users

How to use standard array in C++

4 Answers

0 votes
#include <iostream>
#include <array>
 
template<std::size_t size>
void printArray(std::array<int, size> &arr) {
    for (int i = 0; i < size; i++) {
        std::cout << arr[i] << " ";
    }
}
  
int main() {
    std::array<int, 11> arr { 3, 2, 4, 7, 3, 0, 9, 8, 7, 7, 15 };

    printArray(arr);
}
  
  
  
  
/*
run:
  
3 2 4 7 3 0 9 8 7 7 15 
  
*/

 



answered Dec 8, 2023 by avibootz
0 votes
#include <iostream>
#include <array>

int main() {
    std::array<int, 11> arr { 3, 2, 4, 7, 3, 0, 9, 8, 7, 7, 15 };

    std::cout << arr.front() << "\n";
    
    std::cout << arr.back() << "\n";
}
  
  
  
  
/*
run:
  
3
15
  
*/

 



answered Dec 8, 2023 by avibootz
0 votes
#include <iostream>
#include <array>

int main() {
    std::array<int, 32> arr { 3, 2, 4, 7, 3, 0, 9, 8, 7, 15, 7 };

    std::cout << arr.size() << "\n";
}
  
  
  
  
/*
run:
  
32
  
*/

 



answered Dec 8, 2023 by avibootz
0 votes
#include <iostream>
#include <array>

int main() {
    std::array<int, 6> arr { 3, 2, 4, 7, 3, 0 };

    arr.fill(-1);
     
    for (auto val = arr.begin(); val != arr.end(); val++)  {
    	std::cout << *val << "\n";
    }
}
  
  
  
  
/*
run:
  
-1
-1
-1
-1
-1
-1
  
*/

 



answered Dec 8, 2023 by avibootz

Related questions

...