Skip to main content

CALLING FUNCTION

CALLING FUNCTION:-
                                         IN C LANGUAGE THERE IS TWO TYPES OF CALLING FUNCTIONS .

  1. CALL BY VALUE
  2. CALL BY REFERENCE
* CALL BY VALUE:- 
                                     IN CALL BY VALUE , ORIGINAL VALUE CAN NOT BE CHANGED OR MODIFIED. IN CALL BY VALUE, WHEN THE VALUE PASSED BY THE FUNCTION , IT IS LOCALLY STORE IN THE FUNCTION PARAMETER IN STACK MEMORY LOCATION.
IF YOU CHANGE THE VALUE OF FUNCTION PARAMETER , THE CHANGES MADE TO BE IN LOCAL MEMORY IN CURRENT FUNCTION ONLY BUT IT NOT CHANGE THE VALUE OF VARIABLE INSIDE THE CALLER METHOD SUCH AS MAIN FUNCTION .

SOME IMPORTANT POINTS OF CALL BY VALUE IS :

1.) THIS METHOD COPY THE ORIGINAL VALUE INTO HE FUNCTION AS AN ARGUMENT .

2.) CHANGES MADE TO THE PARAMETER INSIDE THE FUNCTION HAVE NOT EFFECT ON THE ARGUMENT .

3.) ACTUAL AND FORMAL ARGUMENT WILL BE CREATED IN DIFFERENT MEMORY LOCATION .

for example:-  

                      /* swap two numbers by call by value*/

     #include<stdio.h>
    #include<conio.h>
void main() 
{
int a=10,b=20;
printf("value of a and b before swap=%d%d",a,b);
                                                               swap( );                         /*function declaration*/
printf("value of a and b after swap=%d%d",a,b);
getch();
}
                                                        int swap(int a , int b)           /*function definition*/
{
int temp;
temp=a;
a=b;
b=temp;
printf("value of a and b=%d%d",a,b);
}

OUTPUT:-

VALUE BEFORE SWAP     10    20

VALUE AFTER SWAP        20    10

-------------------------------------------------------------------------------------------------------------------------------
*CALL BY REFERENCE:-
                                              IN CALL BY REFERENCE , ORIGINAL VALUE CHANGE OR MODIFIED BECAUSE WE PASS REFERENCE(ADDRESS). ADDRESS OF VALUE PASSED BY THE FUNCTION SO THE ACTUAL AND FORMAL ARGUMENT SHARE THE SAME ADDRESS SPACE .SO ANY VALUE CHANGED INSIDE THE FUNCTION IS REFLECTED INSIDE AS WELL AS OUTSIDE OF THE FUNCTION . 

SOME IMPORTANT POINTS OF CALL BY REFERENCE:

1.)THIS METHOD COPY ADDRESS VALUE INTO FUNCTION AS AN ARGUMENT .

2.)CHANGES MADE TO THE PARAMETER AFFECT THE ARGUMENT BECAUSE IT USED TO ACCESS THE  ACTUAL ARGUMENT .

3.) ACTUAL AND FORMAL ARGUMENT WILL BE CREATED IN SAME MEMORY LOCATION .

for example:-

/*swap two value by call by reference*/

#include<stdio.h>
void main()
{
int a=10, b=20;
printf("value before swap=%d%d",a,b);
                                                            swap(&a,&b);                         /*function declaration*/
printf("value after sap=%d%d",a,b);
}
                                                  int swap(int *a, int *b)        /*function definition*/
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
                                                
output:-

value of a and b before swap                         10      20

value of a and b after swap                             20     10


NOTE:-IF YOU HAVE ANY PROBLEM RELATED TO THIS POST , YOU CAN ASK ME THROUGH COMMENT

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOR MORE KNOWLEDGE CLICK BELOW:-↓↓↓↓↓

basics-of-c-programing-1(preprocessor)

basics-of-c-programming-2.(operators)

basics-of-programming-3-(functions)

which-is-best-intel-or-amd.diffrence-bw-structure-and-union

Comments

Popular posts from this blog

BEST GAMING LAPTOPS FOR HIGH QUALITY/GRAPHICS GAMES

THE BEST GAMING LAPTOPS  NOW-A-DAYS THE TREND OF VIDEO GAMES HAS INCREASED. NEW GENERATION IS ENJOYING VIDEO GAMES VERY MUCH NOW-A-DAYS . MOST OF THE LATEST GAMES ARE COMING UP NOWDAYS WHICH ARE NOT ONLY APPEALING TO CHILDREN BUT  ALSO THE BIG ONES . AND NOWDAYS, GAMES THAT ARE BEING MADE A VERY HIGH QUALITY AND HIGH GRAPHICS IF YOU PLAY SUCH HIGH GRAPHICS GAMES IN A NORMAL LAPTOP THEN THE LAPTOP WILL TURN SLOWER AND HANG IT . THAT'S WHY THERE ARE DIFFERENT GAMING LAPTOPS   COMING FROM SUCH HIGH QUALITY GAMES THAT MUST BE READ BELOW . THE BEST GAMING LA PTO PS ARE FAST CHANGING IN 2019. NOW THAT THE  NEW 20-SERIES GPUs HAVE ST ARTED TO  FILTER INTO OUR FAVOURITE GAMING LAPTOPS MODEL , THE BALANCE OF WHICH ONE IS TRULY   'BEST' IS SHIFTING. WHILE, DOUBT THE BEST GAMING LAPTOP OF LAST YEAR WAS THE MSI GS65 STEALTH THIN , THAT SIMPLY ISN'T IN THE CASE AS WE GET MID-WAY THROUGH 2019. NOW, OUR BEST GAMING LAPTOP IS THE  RAZER BLADE...

How to Make a Bootable Pen drive: A Step-by-Step Guide

  How to Make a Bootable Pen drive: A Step-by-Step Guide   Introduction: In today's digital world, bootable pen drives have become indispensable tools for installing operating systems, running diagnostics, and recovering data. Creating a bootable pen drive is easier than you might think, and this guide will walk you through the process in a simple and straightforward manner. Whether you're a beginner or an experienced computer user, this step-by-step tutorial will help you create your own bootable pen drive effortlessly. Step 1 : Gather the Required Materials To make a bootable pen drive, you'll need the following items: 1. A USB pen drive with sufficient storage capacity (at least 8GB is recommended). 2. The ISO file or installation media of the operating system or tool you want to make bootable (e.g., Windows, Linux, etc.). 3. A computer with an available USB port. Step 2: Download the Required Software To create a bootable pen drive, you'll need specialized software...

Top 6 Best Video Games for 2GB RAM Laptops

Top 6 Best Video Games for 2GB RAM: Game Configurations and Recommended Laptops Introduction: When it comes to gaming, having a high-end gaming rig is often considered essential. However, not everyone has access to a powerful computer with loads of RAM and a dedicated graphics card. But fear not, as there are still plenty of enjoyable gaming experiences available for those with more modest hardware configurations. In this blog post, we will explore the top six best video games that can run smoothly on a system with 2GB RAM. Additionally, we will suggest some good laptops that are suitable for gaming on such specifications. 1. Star dew Valley: - RAM Requirement: 2GB - CPU: 2.00 GHz processor - GPU: Integrated graphics with 256MB video memory Star dew Valley is a relaxing farming simulation game that has captivated players with its charming visuals and engaging gameplay. With its low system requirements, it can run smoothly on systems with 2GB RAM. Download Here:  Star dew valley 2....