recategorized by
591 views
1 votes
1 votes

What is the output of the following c program

void fun1(int *a, int *b, int *c)
{
    *a = *b;
    *b = *c;
    *c = *a;
}

Void fun2(int a, int b, int c)
{
    a = b;
    b = c;
    c = a;
}

int main()
{
    int a = 5, b =10, c =15;
    fun1(&a, &b, &c);
    fun2(a, b, c);
    printf("%d", a+b-2*c);
    return 0;
}
  1. $20$
  2. $40$
  3. $5$
  4. $-5$
recategorized by

1 Answer

1 votes
1 votes
$fun1(\&a, \&b, \&c)$ it's call by reference. Here we will pass the address of a, b, c. After executing this function the values of $a = 10, \: b = 15, \: c = 10$
$fun2(a, b, c)$ it's call by value. After executing $fun2$ the values of $a, b, c$ won't change, because we just pass values to the function. So, the output will be $a + b - 2*c$ is $5$.
Answer:

Related questions

1 votes
1 votes
1 answer
1
1 votes
1 votes
1 answer
2
Applied Course asked Jan 16, 2019
572 views
As traffic congestion plagues every significant road, similarly it also _______ the narrow lanes of the city.clogsobliteratesrestrictsprevents
1 votes
1 votes
1 answer
3
Applied Course asked Jan 16, 2019
640 views
The average of $5$ consecutive numbers is $N$. If the next three numbers are also added, the average shallRemain unchangedIncrease by $1$Increase by $1.5$Increase by $2$