What is the output of the given C programming code? void modify(int arr[], int n)
What is the output of the given C programming code?
#include <stdio.h>
void modify(int arr[], int n)
{
for(int i = 0; i < n; i++)
arr[i] = arr[i] * 2;
}
int main()
{
int data[] = {1, 2, 3, 4};
modify(data, 4);
printf("%d", data[2]);
return 0;
}
Show answerHide answer
Correct answer: (C) 6
Explanation
Arrays are passed as a pointer to their first element, so modify() doubles the original elements: data becomes {2, 4, 6, 8}, and data[2] = 6.