APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY Previous Years Question Paper & Answer

Course : B.Tech

Semester : S1 and S2

Year : 2017

Term : DECEMBER

Branch : BIOTECHNOLOGY

Scheme : 2015 Full Time

Course Code : CS 100

Page:29





PDF Text (Beta):

Roll number: 1
Name: Tom
Marks: 98

5 ஐ. Distinguish call by value and call by reference with the help of examples (10)

Function Call By Value And Call By Reference.
Function Call By Value

For example if we define a function to return the square of a number:

int squared (int i)
/* Squares i */
{ i= i*i;
return
i;
}
then we can test it with this
code:

#include
int
main()

{ int i= 2;

printf ("i squared is

$d\n",squared(i)); printf ("i is
td\n",i);

return 07
0
which will print:

i squared is 4 1 is 2
it will NOT print:

i squared is 4 1 15 4

The reason for this is that functions only have a 10001 copy of the values sent to them. In © this is
known as pass by value or Call by value. Variables passed by value to a function.

Using a function you can create an addition to the C language which takes a number of arguments and
may return a single value.

Call By Reference

void swap(int a, int b) { a
= a+b; b=a-b; a=a-b;

}

Similar Question Papers