There is a parameter passing by value and by reference. I wanted examples to better understand the difference.
There is a parameter passing by value and by reference. I wanted examples to better understand the difference.
In this answer you find the detailed difference between "pass by value" and "pass by reference."
In summary and with examples in VisuAlg, the value tickets are made only copies of the values of the variables passed as parameter.
funcao soma (x,y: inteiro): inteiro
inicio
retorne x + y
fimfuncao
No programa principal deve haver os seguintes comandos:
n <- 4
m <- -9
res <- soma(n,m)
escreva(res)
Passing by reference modifies the variable you pass as a parameter.
procedimento soma (x,y: inteiro; var result: inteiro)
inicio
result <- x + y
fimprocedimento
No programa principal deve haver os seguintes comandos:
n <- 4
m <- -9
soma(n,m,res)
escreva(res)
Examples taken from: The VisuAlg Programming Language
Passing value by reference becomes a feature that offers more dynamics, ie you are telling the compiler where the value is and not telling the value itself, referring to a variable eg would be where it is stored in memory. The opposite would be the parameter-by-value passing, where you simply say that 'variable x equals 10'.