Get the best out of our app
GFG App
Open App
Browser
Continue

# C | Arrays | Question 9

Predict the output of the below program:

 `#include ` `#define SIZE(arr) sizeof(arr) / sizeof(*arr); ` `void` `fun(``int``* arr, ``int` `n) ` `{ ` `    ``int` `i; ` `    ``*arr += *(arr + n - 1) += 10; ` `} ` ` `  `void` `printArr(``int``* arr, ``int` `n) ` `{ ` `    ``int` `i; ` `    ``for``(i = 0; i < n; ++i) ` `        ``printf``(``"%d "``, arr[i]); ` `} ` ` `  `int` `main() ` `{ ` `    ``int` `arr[] = {10, 20, 30}; ` `    ``int` `size = SIZE(arr); ` `    ``fun(arr, size); ` `    ``printArr(arr, size); ` `    ``return` `0; ` `} `

(A) 20 30 40
(B) 20 20 40
(C) 50 20 40
(D) Compile-time error

Answer: (C)

Explanation: The crux of the question lies in the expression: *arr += *(arr + n – 1) += 10; The composite operator (here +=) has right to left associativity. First 10 is added to the last element of the array. The result is then added to the first element of the array.

Quiz of this Question

My Personal Notes arrow_drop_up
Similar Reads