+ 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

28th Jun 2022, 7:52 AM
ABDULKARIM IBRAHIM AMINU
ABDULKARIM IBRAHIM AMINU - avatar
3 Answers
0
Help
28th Jun 2022, 7:53 AM
ABDULKARIM IBRAHIM AMINU
ABDULKARIM IBRAHIM AMINU - avatar
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 }
28th Jun 2022, 8:12 AM
SAN
SAN - avatar