different methods of calling a function

//different methods of calling a function
//1. call by value
//2. call by reference

/*#include <stdio.h>
int add(int x,int y)// function
{
    return x+y;
}

int main()
{
    int r, a=2,b=3;
    r=add(a,b); //function called by value
    printf("%d",r);
    return 0;
}*/

//called by reference--------------------------

#include <stdio.h>
int func1(int  *address)// function
{
    *address=200;
   
}

int main()
{
    int a=2;
    printf("%d\n",a);
    func1(&a); //function called by reference..in this address of value will be given as the argument
    printf("%d",a);
    return 0;
}

Comments

Popular posts from this blog

Tokens in C

Steps taken by a compiler to execute a C program

Variables and Data Types in C