Function Call typesAuthor : Pandu Ranga Rao N
E - Mail : pandu2050@gmail.com

A function execution involves communication between arguments.

Arguments are called as parameters to a function. There are two kinds of arguments which are well known to C developers as, Formal parameters and Actual parameters.

Formal parameters are the values or the variable names which are passed to the function. We can see the formal parameters in the caller function, not in the definition of the function.

Parameters which resides in the definition of a function is called as Actual parameters.

The functions call being carried out with the parameters being passed by two ways.

  1. Call by value
  2. Call by reference
  1. Call by value :
  2. Here the values are passed to the caller function directly. One cannot access the formal parameters and change its value directly. As a result the values will be lost, when the program execution returns back to the caller function from the function, which it is executing.

    Let us look into a program which swaps the values of two integer numbers.


    #include<stdio.h>

    void swap(int, int);

    void main(void)
    {
     int x,y;
     x=10;
     y=20;
     printf("Values before swapping:\n");
     printf("x= %d\ny=%d\n",x,y);
     swap(x,y);
     printf("Values after swapping:\n");
     printf("x= %d\ty=%d\n", x,y);
    }

    void swap(int a,int b)
    {
     int t;
     t=a;
     a=b;
     b=t;
     return;
    }

    The program is written with intension of interchanging two numbers. It does so, but, ultimately it will end up in a result which will be without swapped numbers, because, there is no inter-cross connection between the formal and actual parameters.

  3. Call by reference :
  4. Here, we pass the addresses of the formal parameters, which are pointer variables, to the actual parameters, instead of passing the direct values to the calling function. Pointer variables are used in the actual function definition, which takes address of the formal parameters, which enables one to indirectly access or change the values of the formal parameters.

    For better understanding the concept, we can modify the above program, which will swap two numbers.


    #include<stdio.h>

    void swap(int *, int *);

    void main(void)
    {
     int *x,*y;
     *x=10;
     *y=20;
     printf("Values before swapping\n");
     printf("\nx= %d\ty=%d\n",*x,*y);
     swap(&x,&y);
     printf("Values after swapping\n");
     printf("x= %d\ty= %d", *x,*y);
    }

    void swap(int *a, int *b)
    {
     int t;
     t=*a;
     *a=*b;
     *b=t;
    }

    Here, the elements are swapped, because, we are passing the addresses of pointer variables. The pointing addresses will get interchanged, and automatically the values will also get swapped as an result.


Author : Pandu Ranga Rao N
E - Mail : pandu2050@gmail.com
 
 
 
 
 
 
  About Team ProgrammingBasics.In

Contact Team ProgrammingBasics.In

Instructions for submitting your own article
 
 
X

About Team ProgrammingBasics.In

Right now, we are a small but, dedicated team who strived day and night to alter the pretty old programmingbasics.in into a new conceptual website "The ProgrammingBasics Foundation Library".

The articles and topics in the website are the major contributions of freelancers, programmers across the globe. We thank each of them for their valuable contributions. You can also become a contributor by sending some software related articles to us. We will publish it in our website. Instructions for the same are given in the "Instructions for submitting your own article" page.

Contact Us

ICan Technologies,
HIG 44, 23rd Cross, 8th Main,
E-Block, Vijayanagar 3rd Stage
Mysore-570017, Karnataka, India

Website: www.icantech.in
Mobile: +918050239039

Instructions for submitting your own article

Want to become an article contributor to this site ?

If yes, then send us an article written by you on your own words, neatly typed in MS Word document. If we feel that, you have written the article by using some other article then we will reject the article. Every article we will cross verify, before we publish them. The right to reject the article is with us.

If you want to publish your name and email id's, specify the same in the document.

NOTE: You must give your consent in the email for publishing your email id and your name. Otherwise, your name and email-ids will not get published. We respect your privacy.

One article per document, which means, you must not send more than one article in one document. Everything in the sent document will be treated as one article and your article will get rejected without looking in, further.

The articles must and should be related to computer basics, programming concepts and programming languages. We will not entertain any other topics. Please bear this in your mind, before starting an article write-up.

Articles published in ProgrammingBasics.in are the sole property of ICan Technologies, Mysore. You are here in authorizing ICan Technologies, Mysore to take the ownership of the published article. Rejected articles will not be published and you can try to publish the same in other sites. We will inform you the status of your submitted article within 10 working days, from the date of sent mail. If not responded within 10 days, then you are free to try publishing your article on some other websites. We will simply discard them and will not publish them any further. Once we publish the article, you will not be allowed to publish as it is, in some other website. If we find it, then your article will be removed from site and the removal will be informed to you.

Send your articles to programmingbasics.info@gmail.com with "Article for Publishing" in the subject line.

You must create your own images in PSD (Photoshop Document) only, which is to be supported in CS3 or lower versions. Any animated stuffs, must be in fla files (Flash editable file) and not in any other format and must be readable in Falsh 8.0.

You are now in