#a[(a=b)[3]]

1 messages · Page 1 of 1 (latest)

shy sphinx
#

Can someone explain in layman terms why this will print 1 ? They have posted an explanation but I can't seem to understand it

hardy sparrowBOT
#

<@&987246399047479336> please have a look, thanks.

hardy sparrowBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If your code is long, or you have multiple files to share, consider posting it on sites like https://pastebin.com/ and share the link instead, that is easier to browse for helpers.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

shy sphinx
#

I understand that array a is fully evaluated, so then a is assigned the value of B, but does that mean this assignment disappears completely and has no effect on the rest of the code ?

#

Am I understanding it correctly that in essence it's this?: a[(a=b)[3]]?

quartz rampart
#

I'm kinda reading it as a[b[3]], but no clue if that's right

winter ravine
#

a = b will assign b to a, but also return b to the caller

#

so it makes a = b and then uses that

#

obviously u should never write such terrible code lol

shy sphinx
#

This is for the 1Z0-808 exam, they always use code like this to confuse us for the exam lol

shy sphinx
quartz rampart
shy sphinx
#

Never mind I think I just got it

#

( a [ (a=b)[3]] )

So a is first stored which is: {1, 2, 3, 4)

It then assigns B to A which is {2, 3, 1, 0}
There it grabs index 3 which is 0

Then uses that as an index to search up from the already stored array in a

a[0] = 1

#

@quartz rampart This is correct, right ?

quartz rampart
#

I believe so, yea. The re-assignment appears to be completely useless

shy sphinx
#

Indeed, these exam questions are so confusing it's unreal PePeHands

severe prawn
#

I believe it first accesses 'a' and the assigns b to a and takes the value of b[3] and then a[0]
and if you print the value of a[0] it will diplay 2 since a is actually b now

#

so it does get assigned but is not relevant in that particular statement

quartz rampart
#

In the exam they might have wanted to show off that an array stays the same even when assigned to something else while being accessed

severe prawn
#

possibly. I guess they just wanted to show how arrays are accessed when the same array is assigned to some other array at the same time

shy sphinx
#

Definitely gonna fail this exam lul

#

Thanks for the help boys