0

The output of this code is 1. Can you brief how ?

int * test() { static int x[4]; for(int i=0;i<4;i++){ x[i] = i%2; } return x; } int main() { int * arr = test(); printf("%d", *(arr+3)); }

24th Dec 2018, 9:28 AM
Nipun Jani
2 Answers
+ 7
1
24th Mar 2022, 10:33 PM
abdellali majdoubi
abdellali majdoubi - avatar
- 2
arr stores: {0 [0%2], 1 [1%2], 0 [2%2], 1 [3%2]} *(arr+3): shifts over to element 3 indices away: 1 (explained in 100 characters)
24th Dec 2018, 9:49 AM
👑 Prometheus 🇾🇬
👑 Prometheus 🇾🇬 - avatar