0% found this document useful (0 votes)
3 views

Part 2, C Function Arguments-1

The document outlines the concepts of function arguments in C programming, specifically focusing on 'Call by Value' and 'Call by Reference'. It provides examples for both methods, illustrating how parameters are passed and modified within functions. The document includes code snippets demonstrating the addition of numbers using both techniques.

Uploaded by

haffa138
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Part 2, C Function Arguments-1

The document outlines the concepts of function arguments in C programming, specifically focusing on 'Call by Value' and 'Call by Reference'. It provides examples for both methods, illustrating how parameters are passed and modified within functions. The document includes code snippets demonstrating the addition of numbers using both techniques.

Uploaded by

haffa138
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

COURSE TITLE: COMPUTER PROGRAMMING I

COURSE CODE: CSC 203


NAME OF LECTURER: IBHARALU, F. I.
DEPARTMENT: COMPUTER SCIENCE

1
C Function Arguments

While calling a function, the arguments can be passed to a function in two ways:
 Call by value
 Call by reference

Call by Value
- The actual parameters are passed to the function.
- The actual parameters cannot be modified in the call function.

Call by Reference
- Instead of copying the actual parameters value, its address is passed to
function as parameters..
- Address operator(&) is used in the parameter of the called function.
- Changes in function parameter will change the value of the original variables.

2
Call by Value

Example:

#include<stdio.h>

int sum (int a, int b, int c); //function declaration

int main()
{
//local variable definitions
int answer;
int x = 10;
int y = 5;
int z = 15;

answer = sum (x, y, z); //calling a function to get the sum of values
printf("The sum of three numbers is: %d\n", answer);
return 0;
} 3
//The function returning the addition of three numbers

int sum (int a, int b, int c)


{
return a + b +c;
}

Program Output:
The addition of three numbers is: 30

4
Call by Reference

Example:

#include<stdio.h>

int sum(int *a, int *b); //function declaration

int main()
{
//local variable definitions
int answer;
int x = 10;
int y = 5;

answer = sum (&x, &y); //calling a function to get addition of values


printf("The addition of two numbers is: %d\n", answer);
return 0;
}

5
//function returning the addition of two numbers
int sum (int *a, int *b)
{
return *a + *b;
}

Program Output:
The addition of two numbers is: 15

You might also like