I added one more issue to my little problem
as you can see below I included a 2D array
and a cout line for it in the function.
however, I can't figure out howe to dereference. I tried the & and the * but neither worked :/
Code:#include <iostream> #include <algorithm> constexpr size_t ELEMENTS{ 8 }; constexpr size_t SLOTS{ 32 }; void show(const int(&arr)[ELEMENTS]) { for (const auto& c : arr) std::cout << c; std::cout << '\n'; }Code:void bool_element_option_03(const int(&arr_value)[ELEMENTS], int(&arr_copy_value)[ELEMENTS], int(&arr_elements)[ELEMENTS][SLOTS]) { std::copy(std::begin(arr_value), std::end(arr_value), std::begin(arr_copy_value)); std::sort(std::rbegin(arr_copy_value), std::rend(arr_copy_value)); for (int var_ones_index = 0; var_ones_index < SLOTS; var_ones_index++) { // returning addresses; not sure how to dereferecne this std::cout << arr_elements[ELEMENTS * SLOTS + var_ones_index] << std::endl; } std::cout << "\nReverse sorted:\n"; show(arr_copy_value); }Code:int main() { const int arr_value[ELEMENTS]{ 1, 2, 9, 4, 5, 6, 7, 8 }; int arr_copy_value[ELEMENTS]{}; int arr_elements[ELEMENTS][SLOTS]; for (int var_create_array_a = 0; var_create_array_a < ELEMENTS; var_create_array_a++) { for (int var_create_array_b = 0; var_create_array_b < SLOTS; var_create_array_b++) { arr_elements[var_create_array_a][var_create_array_b] = 0; } } std::cout << "\nOriginal order:\n"; show(arr_value); bool_element_option_03(arr_value, arr_copy_value, arr_elements); }




Reply With Quote
