Parameter passing Method and build in function

 PARAMETER PASSING METHOD :

          parameter passing method is depending upon the values or pointing address are passed as an argument to a function. In this parameter passing method has two types.

                   1------->  call by value or Pass by value 

                   2-------->   call by Reference or Pass by reference

CALL BY VALUE:

                   The method of passing arguments by value is also known as call by value. In this method, the values of actual arguments are copied to the formal parameters of the function. Even though values of formal arguments are changed in the function it will not reflect back into calling / main program because we are giving only a copy of the actual argument values. Once the control returns back to the calling function the changes made in the called function will be disappeared.


#include<stdio.h>
void swap(int x,int y);
int main(){
                int a, b;
                printf("enter the two values:\n");
                scanf("%d\n%d",&a,&b);
                printf("before swapping function  : a=%d  b=%d \n ",a,b);
                swap(a,b);
                printf("after calling the swapping function : a=%d  b=%d \n ",a,b);
               return 0;
}
void swap(int x,int y){
        int temp;
        temp=x;
        x=y;
        y=temp;
        printf("value in swapping function: a=%d  b=%d \n",x,y);
 }

output:


enter the two values:
4
6
before swapping function  : a=4  b=6
value in swapping function: a=6  b=4
after calling the swapping function: a=4  b=6

call by Reference :

          The  method of passing arguments by address or reference are also known as call by reference.In this method, the addresses of the actual arguments are passed to the formal parameters of the function.
If the arguments are passed by reference, the changes made in the function (formal parameters) will be reflected back in the called function (actual arguments). The values of the actual arguments are not safe because we are giving the original address of the arguments.

#include<stdio.h>
void swap(int *x,int *y);
int main(){
                int a, b;
                printf("enter the two values:\n");
                scanf("%d\n%d",&a,&b);
                printf("before swapping function  : a=%d  b=%d \n ",a,b);
                swap(&a,&b);
                printf("after calling the swapping function : a=%d  b=%d \n ",a,b);
               return 0;
}
void swap(int *x,int *y){
        int temp;
        temp=*x;
        *x=*y;
       * y=temp;
        printf("value in swapping function: a=%d  b=%d \n",*x,*y);
 }

output:


enter the two values:
5
8
before swapping function  : a=4  b=6
value in swapping function: a=8  b=5
after calling the swapping function: a=8  b=5


















 LIBRARY FUNCTION OR BUILT-IN FUNCTION :

 A predefined function is also called a library function or built-in functions. These functions are already written by the software provider. And all the functions are available in our system. We can only use the build-in functions on our program. we cannot do modify the function. these functions are grouped stored in library functions. Where we used this library function in our means, while we are starting the program first we have to insert some header files like #include<stdio.h>, #include<conio.h>   these are the library functions, each library function having some build-in function, an example of the build-in functions are following,




The above two library functions are commonly using in all the c program code. 
#include<stdio.h>  
                                 this the standard library function for accessing scanf() function and printf() functions.While writing a C-program, first you have to include these library functions on your the program then only you can able to access prinf() functions and scanf(). You missed the function means your program will not execute, it will only appear error on your screen.

#inlcude<conio.h>     
                                this library function used for clearing our output screen. sometimes we get overlapping output on our screen, which it makes confused and very difficult to find our outputs. So that we use a clear screen ( clrscr() ) , this function only present in the conio library, once you used this library function for returning you have to do mention getch() instead of return 0 or return 1.

#include<stdlib.h>
                    it normally called standard functions. when you use the pointer program or implementing a data structure you must include this library function.

#include<string.h>
                      this library function usually called the string manipulating function.  the example of string manipulation library function    see example
   

#include<math.h>
                 this function used for doing mathematical  expression.
   

function

    meaning

  example

sqrt(x)

 square root

sqrt(4)

 log(x)

 logarithm base 10

log(5)

abs(x)

absolute value of integer

abs(-20)

fabs(x)

absolute values of float

abs(-2.3)

exp(x)

eexponentiation

exp(5)

pow(x,y)

x raise to the power y

pow(4,6)

ceil(x)

rounding x to the next smallest vlaues

ceil(4.5)

floor(x)

 rounding x to the next highest values

floor(4.5)

fmod(x,y)

return the remainder of x/y

fmod(5,1)

rand()

generate random integer

rand()

sin(x)

find sin value

sin(4)

cos(x)

find cosine value

cos(5)

tan(x)

find tan value

tan(5)

 






No comments:

Post a Comment