What is wrong with the question?

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
Recently I come across a programming test question in real life. I'm not the candidate and neither did I set this question.
The codes are irrelevant to what I'm asking. Lets see if any keen eyes, especially those that think programming is simple just copy and paste realise the glaring mistake with the question.
If you can provide code example to illustrate your answer, even better!

oA6Wzb6.png
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
I don't know JS. But from my research, JavaScript will pass by value. In the case where another variable is assigned to variable, then that value will be the value of the variable "reference". Technically, pass by reference is not strictly correct

Ref: https://www.w3docs.com/snippets/jav...s-by-reference-or-pass-by-value-language.html
Well done.... There is no pass-by-reference in Javascript nor in Java nor in quite a number of programming languages out there.

Now.. show us which programming language has pass by reference and how it works.
:)
 

Trader11

Banned
Joined
Oct 14, 2018
Messages
15,698
Reaction score
5,233
Well done.... There is no pass-by-reference in Javascript nor in Java nor in quite a number of programming languages out there.

Now.. show us which programming language has pass by reference and how it works.
:)
今晚赏月先。。。。
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
Find out yourself for your own good.
Are you sure ?
Absolutely sure ?
LOL.
C++:
#include <iostream>

using namespace std;

void mutator(int &i) {
  i = 123;
}

int main(int argc, char** argv) {

  int i = 456;
  cout << i << endl;
  mutator(i);
  cout << i << endl;

  return 0;
}
Code:
$ ./passbyref
456
123

PHP:
<?php

function mutator(&$i) {
  $i = 456;
}

$i = 123;
print "$i\n";
mutator($i);
print "$i\n";

?>
Code:
$ php passbyref.php
123
456
 

sunny189

Junior Member
Joined
May 13, 2005
Messages
91
Reaction score
63
Well done.... There is no pass-by-reference in Javascript nor in Java nor in quite a number of programming languages out there.

Now.. show us which programming language has pass by reference and how it works.
:)
Hello there are popular language support referencing and its very easy to understand. I will just quote from the manual so nothing special from my end

In PHP:

Code:
<?php
function foo(&$var)
{
    $var++;
}

$a=5;
foo($a);
// $a is 6 here
?>

In C#


Code:
void Method(ref int refArgument)
{
    refArgument = refArgument + 44;
}

int number = 1;
Method(ref number);
Console.WriteLine(number);
// Output: 45

I personally don't use reference alot because it will easily introduce bugs and hard to debug on data.
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top