+ 1
Hello guys, why is the output 1 in c?
#include<stdio.h> 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)); } Output: 1
3 Answers
0
Help
0
#include<stdio.h>
int * test() {
static int x[4];
for(int i=0; i<4; i++) {
x[i] = i%2;
}
printf("%d",x[0]); // 1st element of array
printf("%d",x[1]); // 2nd element of array
printf("%d",x[2]); // 3rd element of array
printf("%d\n",x[3]); // 4rd element of array
return x;
}
int main() {
int * arr= test();
printf("%d",*(arr+0)); // 1st element of array
printf("%d",*(arr+1)); // 2nd element of array
printf("%d",*(arr+2)); // 3rd element of array
printf("%d",*(arr+3)); // 4rd element of array
}