Wednesday, 15 September 2010

function - Parameter Passing in C - Pointers, Addresses, Aliases -


Can someone please understand the difference between parameters passed in C ? According to Professor notes there are 4 different ways to pass the parameter

  1. Call-by-value
  2. Call-by-address (pointer)
  3. Call If you can kindly give an example, I appreciate it, and your work will be appreciated.

  1. call-by-value

    Passing the value of a function as the parameter if the function modifies the variable, the actual variable will not change .

      Zero Funny 1 (Intmuprum) {myParam = 4; } Zero main () {int myValue = 2; Fun1 (myValue); Printf ("myValue =% d", myValue);  

    myValue will always be 2.

  2. Call-by-address (pointer)

    Fun to zero 1 (Int * MyMuram) {* MyParam = 4; } Zero main () {int myValue = 2; Fun1 (& myValue); Printf ("myValue =% d", myValue); }

    Here we are giving the address of myValue to fun1 . Therefore the value of myValue will be 4 at the end of main () .

  3. Call-by -Lyas

    According to my understanding there is no surname in C. It should be the C ++ reference mechanism.

  4. global variable / static variable

    The general location accessible by a collar and cali functions is both the calling The ones and colleagues will be able to access and modify them.

      int myValue = 2; Zero Funny 1 () {myValue = 4; } Zero main () {myValue = 2 fun1 (); Printf ("myValue =% d", myValue); }  

    As you can guess, the value of myValue will be 4 at the end of main () .

Hope it helps.


No comments:

Post a Comment