Recently I encountered this puzzle :
int main(){
int arr[7];
int b,c,d,a;
a=4;
printf("%d",arr[?]);
return 0;
}
The question is to Replace “?” with a integer so that output is 4. I am not sure but I don’t think this is solvable in a standard way ?! (Not invoking Undefined Behavior or depending on implementation) If NO, then I am very interested in knowing how ?
Edit:This task is taken from here, I tried to solve with 10, but sadly it’s not the answer the problem setter wants.However, I solved it using some pretested implementation dependent mumbo-jumbo,but I really have no explanation for how it really works!
Here is the answer : SPOILER,You are welcome to explain it
Assuming there is no answer that conforms to the standard, could you use an operation (obviously not an integer) like arr[&a-arr]?
Edit: Made cleaner thanks to Ben and others in the comments.