Thursday, July 30, 2009

Can you give an example of pass by value and reference on turbo c?

pass by value is when only the value of a variable gets changed within a function and is passed to a function like





func(a)





as oppsoed to pass by reference which will chang the data held at the memory register.





func(*a) would pass a pointer to the variable a, and therfore you could modify the contents of that memory

Can you give an example of pass by value and reference on turbo c?
Turbo C? Wow, that certainly brought back my memory...





C language always pass by value.





int func(int a, int b) { .... }





When called by func(x,y), the values of x and y are copied to a and b, respectively.





To do call by reference in C, you do





int func(int* a, int* b) { ... }





When you call this by doing func(%26amp;x, %26amp;y), you copies the ADDRESS of variable x and y to a and b. When you do:





*a=100;





You assign 100 to the address of x.
Reply:Visit my blog http://codesbyshariq.blogspot.com for more information on programs and also visit my previous answers.


No comments:

Post a Comment