Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

10
Feb

How to distinguish parameter passing techniques?

Related Blog Items

Before we see what the output of the program shown below is, let us learn how to distinguish two parameter passing techniques: pass by value and pass by address. Keep the following rule in mind:
If the declaration of argument matches the declaration of the formal parameter, then the argument is passed by value. To be more specific, C provides only call-by-value parameter passing.

#include
int main ( void )
{
  char *a =  "abc";
  void f ( char * );   

  f ( a );
  puts ( a );
}   

 void    f ( char *a )
{
   a++;
}

In the above example, the declarations of argument "a", and the formal parameter "a", both are same. That means the variable "a" has been passed by value! But, "a" stands for the address the string, and hence the string has been passed by address. Naturally, only the modification to the object pointed by the pointer (not in this case) has reflection in the main (), but any modification of "a" has no effect. Hence the output of this program is: abc.

Popularity: 4%

You need to log on to convert this article into PDF


Related Blog Items

No Comments

No comments yet.

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image