How to declare array size with constexpr in c++

1 Answer

0 votes
// constexpr is a value that will not change (static) and is set at the compilation time

#include <iostream>

constexpr int size = 4;

int main()
{
    int arr[size] = {3, 9, 8, 1};
    
   for (int i = 0; i < size; i++) {
        std::cout << arr[i] << "\n";
    }
}


/*
run:

3
9
8
1

*/

 



answered Sep 17, 2024 by avibootz

Related questions

1 answer 175 views
1 answer 192 views
1 answer 228 views
1 answer 315 views
1 answer 235 views
235 views asked Dec 4, 2020 by avibootz
1 answer 326 views
...