C Programming For Beginners And Advanced - Programming In C: C Programming A Modern Approach - C Programming Book For Beginners To Advanced by Patil Kunal
Author:Patil, Kunal [Patil, Kunal]
Language: eng
Format: epub, azw3, pdf
Publisher: UNKNOWN
Published: 2021-05-07T00:00:00+00:00
The called function receives the information from the calling function through the parameters. The variables used while invoking the calling function are called actual parameters and the variables used in the function header of the called function are called formal parameters.
C provides two mechanisms to pass parameters to a function.
1 : Pass by value (OR) Call by value.
2 : Pass by reference (OR) Call by Reference.
1 : Pass by value (OR) Call by value :
In call by value, value being passed to the function is locally stored by the function parameter in stack memory location. If you change the value of function parameter, it is changed for the current function only. It will not change the value of variable inside the caller method such as main().
Or
When a function is called with actual parameters, the values of actual parameters are copied into formal parameters. If the values of the formal parametes changes in the function, the values of the actual parameters are not changed. This way of passing parameters is called pass by value or call by value.
Ex :
#include<stdio.h>
#include<conio.h>
void swap(int ,int );
void main() {
int i,j;
printf("Enter i and j values:");
scanf("%d%d",&i,&j);
printf("Before swapping:%d%d
",i,j);
swap(i,j);
printf("After swapping:%d%d
",i,j); getch();
}
void swap(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
}
Output
Enter i and j values: 10 20 Before swapping: 10 20
After swapping: 10 20
2 : Pass by reference (OR) Call by Reference : In pass by reference, a function is called with addresses of actual parameters. In the function header, the formal parameters receive the addresses of actual parameters. Now the formal parameters do not contain values, instead they contain addresses. Any variable if it contains an address, it is called a pointer variable. Using pointer variables, the values of the actual parameters can be changed. This way of passing parameters is called call by reference or pass by reference.
Ex : #include<stdio.h>
#include<conio.h>
void swap(int *,int *);
void main()
{
int i,j;
printf("Enter i and j values:");
scanf("%d%d",&i,&j);
printf("Before swapping:%d%d
",i,j);
swap(&i ,&j);
printf("After swapping:%d%d
",i,j);
}
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
Output Enter i and j values: 10 20
Before swapping:10 20
After swapping: 20 10
Differnce between Call by value and Call by reference
Call by value Call by Reference
1 : When a function is called the values of variables are passed
1 : When a function is called the address of variables are passed.
2 : Change of formal parameters in the function will not affect the actual parameters in the calling function. 2 : The actual parameters are changed since the formal parameters indirectly manipulate the actual parametes.
3 : Execution is slower since all the values have to be copied into formal parameters. 3 : Execution is faster since only address are copied.
1 : Functions with no Parameters and no Return Values.
2 : Functions with no Parameters and Return Values.
3 : Functions with Parameters and no Return Values.
4 : Functions with Parameters and Return Values.
1 : Functions with no Parameters and no Return Values : 1 : In this category, there is no data transfer between the calling function and called function.
2 : But there is flow of control from calling function to the called function.
3 : When no parameters are there , the function cannot receive any value from the calling function.
Download
C Programming For Beginners And Advanced - Programming In C: C Programming A Modern Approach - C Programming Book For Beginners To Advanced by Patil Kunal.azw3
C Programming For Beginners And Advanced - Programming In C: C Programming A Modern Approach - C Programming Book For Beginners To Advanced by Patil Kunal.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Ada | Ajax |
Assembly Language Programming | Borland Delphi |
C & C++ | C# |
CSS | Compiler Design |
Compilers | DHTML |
Debugging | Delphi |
Fortran | Java |
Lisp | Perl |
Prolog | Python |
RPG | Ruby |
Swift | Visual Basic |
XHTML | XML |
XSL |
Hello! Python by Anthony Briggs(9397)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9360)
The Mikado Method by Ola Ellnestam Daniel Brolund(9325)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(7870)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7414)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7360)
Grails in Action by Glen Smith Peter Ledbrook(7311)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7137)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(5975)
Kotlin in Action by Dmitry Jemerov(4660)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(3928)
Functional Programming in JavaScript by Mantyla Dan(3729)
Learning Java by Patrick Niemeyer & Daniel Leuck(2877)
Mastering Python for Finance by Weiming James Ma;(2855)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(2849)
Windows APT Warfare by Sheng-Hao Ma(2814)
WordPress Plugin Development Cookbook by Yannick Lefebvre(2630)
Mastering Java 9 by Dr. Edward Lavieri(2577)
Architecting Modern Java EE Applications: Designing lightweight, business-oriented enterprise applications in the age of cloud, containers, and Java EE 8 by Daschner Sebastian(2566)