Tarea 1 Compiladores

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Problema 1

Consider the following code written in C notation:

int ff(int x, int y) {

int d = 0;

while (x >= y) {

d++;

x = x - y;

return d;

int main () {

int a, b, c;

a = 25;

b = 7;

c = ff(a, b);

What are the values of a, b and c after the code execution in each of the following cases?

1. Parameter passing is by value.

A=25 b= 7 c=3

2. Parameter passing is by reference.

A=4 b=7 c=3

3. Parameter passing is by name. Assume that the return instruction assigns the value of
d to c.

A=4 b=7 c=3


Problema 2 Consider the following code written in the C syntax:

void inc(int x) {

x++;

void div(int x, int y) {


x = x/y;
}
void f (int x, int y) {
if (x >= 0 ) {
x = x + x;
} else {
y = y + x; 7,3
}
}
void main() {
a = 0; //Profesor, al hacer la funcion div, se hace 3/0, por lo que us los siguientes valores a=2 b=6
b = 3;
c=f(inc(b), div(b,a));
}
Which are the values of a, b and c after the execution of the program in each of the following
cases?:

1. Using parameter passing by value.

A=2 b=6 c= 14

2. Using parameter passing by reference

A=2 b=3 c= 14

3. Using lazy evaluation.

A=2 b=6 c= 14

Problema 3 There are languages, like ADA, that use a call by result and value-result. Describe both
methods of parameter passing and give examples of how they work.

You might also like