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 89 views
1 answer 110 views
1 answer 152 views
1 answer 205 views
1 answer 140 views
140 views asked Dec 4, 2020 by avibootz
1 answer 220 views
...