Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Function calling in C language, call by value, call by refrence, difference

Rating
-
Sold
-
Pages
3
Uploaded on
27-05-2025
Written in
2024/2025

Function calling in C programming language 1. Call by value 2. Call by refrence 3. Swapping 4. Difference between call by value and refrence

Institution
Course

Content preview

Function Calling in C (call by value and call by reference)

Calling a function
When a program calls a function, the program control is transferred to the called function. A
called function performs a defined task and when its return statement is executed or when its
function-ending closing brace is reached, it returns the program control back to the main
program.

To call a function, you simply need to pass the required parameters along with the function
name, and if the function returns a value, then you can store the returned value.

Control of the program is transferred to the user-defined function by calling it.

Syntax of function call
functionName(argument1, argument2, ...);

In the above example, the function call is made using addNumbers(n1, n2); statement inside the
main() function.

Call by Value and Call by Reference
Functions can be invoked in two ways: Call by Value or Call by Reference. These two ways
are generally differentiated by the type of values passed to them as parameters.

The parameters passed to function are called actual parameters whereas the parameters received
by function are called formal parameters.

Call By Value in C: In this parameter passing method, values of actual parameters are copied to
function’s formal parameters and the two types of parameters are stored in different memory
locations. So any changes made inside functions are not reflected in actual parameters of caller.

In other words, in this parameter passing method, values of actual parameters are copied to
function's formal parameters, and the parameters are stored in different memory locations. So
any changes made inside functions are not reflected in actual parameters of the caller.

Call by Value Example: Swapping the values of the two variables

1. #include <stdio.h>
2. void swap(int , int); //prototype of the function
3. int main()
4. {
5. int a = 10;
6. int b = 20;
7. printf("Before swapping the values in main a = %d, b = %d\n",a,b);
8. swap(a,b);
9. printf("After swapping values in main a = %d, b = %d\n",a,b); }
By: Pragya Singh Tomar
Page 1 ICS,Vikram University, Ujjain

Written for

Institution
Course

Document information

Uploaded on
May 27, 2025
Number of pages
3
Written in
2024/2025
Type
Class notes
Professor(s)
Arohi patel
Contains
All classes

Subjects

$3.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
ditithakkar

Also available in package deal

Get to know the seller

Seller avatar
ditithakkar KPGU
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
20
Last sold
-
STUDY FROM THE BEST

PROGRAMMING languages C, C++, SQL PLUS, ADVANCE Mathematics, English Language Ethics and many more

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions