1,311 views
0 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 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
Position:
Show:

Related questions

7 7 votes
1 1 answer
206
206 views
GO Classes asked Jun 6
206 views
What is the output of the following code?#include <stdio.h void fun() { static int x = 3; int y = 2; x = x + y; y = y + x; printf("%d ", x); } int main() { fun(); fun(); ...
2 2 votes
1 answers 1 answer
1.5k
1.5k views
suneetha asked Aug 31, 2017
1,459 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 1 vote
0 0 answers
359
359 views
Amit puri asked Sep 22, 2016
359 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 program will b...
7 7 votes
1 1 answer
212
212 views
GO Classes asked Jun 6
212 views
What is the output of the following code?#include <stdio.h void change(int *p, int *q) { *p = *p + 4; *q = *p + *q; p = q; *p = *p - 3; } int main() { int a = 6, b = 10; ...