636 views
0 votes
0 votes

How can we identify whether a function is call by value or call by refrence?? 

by looking at the defination or by looking at the statement where it is called.

please someone explain

1 Answer

0 votes
0 votes
Actually in C, only call by value is possible

In GATE, they give the question with call by value but they can say what happened if it is call by reference. then simply u can assume like it is a global variable.

void change(int a,int b)

{

     int temp=a;

     a=b;

     b=temp;

}

int main()

{

       int i1=10,i2=20;

      swap(i1,i2);

      printf("i1 = %d, i2 = %d \n");

}

o/p :-  i1=10,i2=20 ------------ by default, as per C, call by value

o/p :- i1=20,i2=10 -----------  if they specified call by reference

 

Credit to @ Arjun sir
edited by

Related questions

2 votes
2 votes
1 answer
1
suneetha asked Aug 31, 2017
1,087 views
#include <stdio.h #include <stdarg.h int fun(int n, ...) { int i, j = 1, val = 0; va_list p; va_start(p, n); for (; j < n; ++j) { i = va_arg(p, int); val += i; } va_end(p...
1 votes
1 votes
0 answers
2
Amit puri asked Sep 22, 2016
201 views
int main(){Char *str=”Gate2017”;printf(“%d”, fun( str ));return 0;}int fun(char *P1){Char *P2=P1;while (*++P1) return (P1-P2);}The output of the above progra...