edited by
732 views

3 Answers

0 votes
0 votes
on calling f() new activation record pushed and its local variables x and y get value 5 each. now x-- will make x 4 and y=y+15 make y 20 but there will be no effect on a ie actual variable so answer would be 5
0 votes
0 votes

The answer would be either 4 or 20.
Let me tell you why basically Call by Copy/Restore is a special case of call-by-reference where the provided reference is unique to the caller. The final result of the referenced values will not be saved until the end of the function

The actual implementation of above program would be :

#include <stdio.h>
void f(int x, int y){
    x--;
    y=y+15;
}
int main(void)
{
    int a = 5;
    {
    int cr_0000 = a;    // Copy for first argument
    int cr_0001 = a;    // Copy for second argument
    incr(&cr_0000, &cr_0001);
    a = cr_0001;        // Restore for second argument
    a = cr_0000;        // Restore for first argument
    }
    printf("%d\n", a);
    return 0;
}

Now as you can see it depends on programmer which value he/she pick and thus answer would change accordingly.

Reference :https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_copy-restore

Related questions

1 votes
1 votes
0 answers
2
1 votes
1 votes
1 answer
3
Vasu Srivastava asked Aug 18, 2017
1,047 views
#include <stdio.h int main(void){ int i=511; char *p = (char *)&i; printf("%d", *p); }OK so why take 2's complement and not simple binary number? Means, why is C giving -...
0 votes
0 votes
1 answer
4
Psnjit asked Jan 12, 2019
1,153 views
main(){unsigned int i= 255;char *p= &i;int j= *p;printf("%d\n", j);unsigned int k= *p;printf("%d", k);} Both the outputs are -1. I have even tried with - int i = 255(3rd ...