Does call by reference actually exist in c

hi,

when dealing with arrays we often come across mechanism that seems to implement call by reference, of course, during function calls.

Is it not the violation of the fact that 'all function calls in c are by value only', or is there any mechanism other than call by reference and call by value that is being implemented?

kindly explain...

Replies

  • Anoop Kumar
    Anoop Kumar
    When ever you pass a variable to function in arguments, it's pass by reference.
    When you use pointers its pass by reference, as pointer directly points to original address.
     Pass by value
     
    void foo(int j) {
      j = 0;  /*  modifies the copy of the argument received by the function  */
    }
     
    int main(void) {
      int k=10;
      foo(k);
      /*  k still equals 10  */
    }
     
    pass by refence.
     
    If you do want a function to modify its argument you can obtain the desired effect using pointer arguments instead:
     
         
     
    void foo(int *j) {
      *j = 0;
    }
     
    int main(void) {
      int k=10;
      foo(&k);
      /*  k now equals 0  */
    }
    
    #-Link-Snipped-#:
  • rahul69
    rahul69
    Arrays are always passed by reference, regardless of C or C++. In C++, pass by reference takes place by use of '&' and in C, the same reference is done using pointers😀
  • Vishal Sharma
    Vishal Sharma
    actually, while passing array you don't even need to write '&'
  • Ankita Katdare
    Ankita Katdare
    That is a good question. I want to know, where did you get
    violation of the fact that 'all function calls in c are by value only'
    that from? Is it mentioned in some book?

You are reading an archived discussion.

Related Posts

- How about introducing "Best Answer" option ? The CEan who asks the question has right to vote for "Best Answer" to whoever's answer he/she finds "most-helpful". If CEan who...
why we use superposition principle in derivation of schoridinger wave equation?????????????
is the statement regarding wave function correct or not --------justifyy ur answer- "periodic variations of wave function gives rise to the deBroglie waves or matter waves associated with the moving...
I'm looking for an opinion on setting up a home network to connect computers and networking enabled devices. If the locations of the gadgets are fixed - would you recommend...
We're talking about home wireless router security for your regular wi-fi connections. The Linksys routers provide following security modes: WEP, WPA-Personal, WPA2-Personal, WPA-Enterprise, WPA2-Enterprise, or RADIUS and I see that...