Module 3
Module 3
24 15 34
26 134 194
67 23 345
• Then the compiler will assume its all rest value as 0,which are not defined.
• Mat[0][0]=11, Mat[0][1]=0, Mat[0][2]=0
• Mat[1][0]=12, Mat[1][1]=13, Mat[1][2]=0
• Mat[2][0]=14, Mat[2][1]=15, Mat[2][2]=16
• Mat[3][0]=17, Mat[3][1]=0, Mat[3][2]=0
return (value);
}
• The return_value_Datatype denotes the datatype of the value that function returns
• The arguments in the function definition are known as formal
arguments/parameters
• The body
20-10-2023of the function is the statements orBblock
Prof. Shilpa V which consists of local variable
32
User Defined Functions arguments list
• Example:
Return_type function_name(datatype 1 arg 1, datatype2 arg2, …)
• Formal Arguments
• The arguments that are mentioned in function definition are called formal arguments or dummy
arguments , that just hold the copies of the actual parameter values that are sent by the calling
function through the function call.
• These arguments are like other local variables which are created when the function call starts and
destroyed when the function ends.
• Order20-10-2023
number and type of actual arguments inProf.
the function
Shilpa BV call should be match with the order
35
# include<stdio.h>
int add3num(int, int, int); // Optional – Prototype – FUNCTION DELARACTION
void main( ) // Calling Function
{
int n1, n2, n3, result; Actual parameters n1, n2, n3
printf(“Enter 3 numbers”);
n1 = 20
scanf(“%d%d%d”, &n1, &n2, &n3);
result = add3num(n1,n2,n3); // FUNCTION CALL n2 = 25
printf(“Sum of 3 numbers = %d”, result);
n3 = 14
}
to a function
#include <stdio.h> void displayNumbers(int num[ ][2])
void displayNumbers(int num[2][2]); {
// code
void main( ) }
{
int num[5][5], n, m, i; OR
return; return;
}
20-10-2023 } Shilpa B V
Prof. 52
Function to perform linear search.
#include <stdio.h> int main()
{
int arr[10] , size, key, position;
int linear(int* arr, int size, int key)
printf(“Enter the size of array\n”);
{
scanf(“%d”, &size);
int i; printf(“Enter the array elements\n”);
for ( i = 0; i < size; i++) for ( i = 0; i < size; i++)
{ scanf(“%d”, &arr[i]);
if (arr[i] == key) position = linear(arr, size, key);
return i; if (position == -1)
printf(“\nKey not present");
}
else
return -1;
printf(“\nKey present at %d position", position);
}
return 0;
20-10-2023 } Prof. Shilpa B V 53