Write a C++ program defining a function that takes a reference to an array (`int (&arr)[N]`) and doubles its elements.
First line: N. Second line: N space-separated integers.
Print doubled array elements separated by a space.
1 <= N <= 10
4 1 2 3 4
2 4 6 8
C++ allows passing exact-sized array references without decaying to raw pointers.
#include <iostream>
template <size_t N>
void doubleArray(int (&arr)[N]) {
for (size_t i = 0; i < N; i++) arr[i] *= 2;
}
int main() {
int n;
if (std::cin >> n) {
int arr[10];
for (int i = 0; i < n; i++) std::cin >> arr[i];
doubleArray(arr);
for (int i = 0; i < n; i++) {
std::cout << arr[i];
if (i < n - 1) std::cout << " ";
}
std::cout << "n";
}
return 0;
}Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used