969 views
1 votes
1 votes
int i = 1;
int main()
{
    int a[]= { 0,1, 2} ;
    f(a[i], i);
    printf("%d", a[i]);
}

void f(int x, int y)
{
    y++;
    x=5*i;
}


In above function f() uses " call by name" technique, what is the output printed?

a) 2        b) 10           c) 5         d) 1

4 Answers

Best answer
6 votes
6 votes
Using a C style creates confusion for call by name. The scope of variables comes from the function where it is called (dynamic scoping) in call by name.

y++; i becomes 2

x = 5*i; a[2] becomes 10.

So, 10 should be printed.
selected by
2 votes
2 votes
The output printed is 1 i.e., option d). The function f() doesn't return any value neither does it make changes in the original value of a[i] and hence no matter what goes inside the body of f(), the output will be the initial value of a[i] i.e., 1.
1 votes
1 votes
option b .

as per concept of macro implementation in c,

http://www.cs.rit.edu/~rpj/courses/plc/lab4/lab47.html#Q12
1 votes
1 votes
D should be the answer. this is call by value so a[i] is unchanged.

Related questions

0 votes
0 votes
1 answer
1
Isha Karn asked Dec 9, 2014
523 views
void main() { int x=10, y=5; swap(x,y); print(x,y); } void swap(int a, int b) { int c, x=0; c=a; a=b; b=c; }what is output using call by text?a) 5 0b) 5 10c) 10 0d) ...
0 votes
0 votes
1 answer
2
shree asked Nov 22, 2014
519 views
What will be the second value printed by the program if parameter passing mechanism is call by reference?int b=10 //global begin procedure func(int x,int y) begin print(b...
0 votes
0 votes
1 answer
4
Rohit Gupta 8 asked Nov 8, 2017
7,114 views
Let A be a square matrix of size n x n. Consider the following program. What is the expected output?C = 100 for(i=0; i<n; i++) for (j=0; j<n; j++) { Temp = A[i][j] + C A[...