Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to solve this?

Tags:

c++

c

puzzle

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

like image 937
Quixotic Avatar asked Nov 09 '10 03:11

Quixotic


People also ask

Who Solved hardest math problem?

When we recently wrote about the toughest math problems that have been solved, we mentioned one of the greatest achievements in 20th-century math: the solution to Fermat's Last Theorem. Sir Andrew Wiles solved it using Elliptic Curves.

Can I solve math on Google?

Google Lens can solve simple equations such as “5+2” or more complex formulas such as “x2 – 3x + 2.” You can scan the problem from a real-world piece of paper or from a digital display. Open the “Google” app on your Android phone or tablet, iPhone, or iPad.

Can math solve all problems?

Math alone cannot solve deeply-rooted societal problems, and attempting to rely on it will only reinforce inequalities that already exist in the system.


1 Answers

In most implementations, arr[10] (or 7) will be 4, since the locals will be laid out sequentially.

However, this is neither defined nor standard, and must not be relied on.

like image 179
SLaks Avatar answered Oct 16 '22 12:10

SLaks