10.09.2013 Views

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />

Here the value to function interchange is passed by value.<br />

Consider program2<br />

main()<br />

{<br />

int x=50, y=70;<br />

interchange(&x,&y);<br />

printf(“x=%d y=%d”,x,y);<br />

}<br />

interchange(x1,y1)<br />

int *x1,*y1;<br />

{<br />

int z1;<br />

z1=*x1;<br />

*x1=*y1;<br />

*y1=z1;<br />

printf(“*x=%d *y=%d”,x1,y1);<br />

}<br />

Here the function is called by reference. In other words address is passed by<br />

<strong>using</strong> symbol & and the value is accessed by <strong>using</strong> symbol *.<br />

The main difference between them can be seen by analyzing the output of<br />

program1 and program2.<br />

The output of program1 that is call by value is<br />

x1=70 y1=50<br />

x=50 y=70<br />

But the output of program2 that is call by reference is<br />

*x=70 *y=50<br />

x=70 y=50<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 63 ‐

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!