Function Call C Language
Function Call C Language
PROGRAMMING IN C
Function call C Programming
• Function call is a process to execute function by its
name in main function.
Value
Original value not modified. The original value is modified.
modification
Actual arguments are not Safe.
Actual arguments remain safe They can be accidentally
Safety as they cannot be modified modified, so you need to
accidentally. handle arguments operations
carefully.
Recursion in C Programming
abc();
}
void abc()
{
abc();
}
Recursion Process
Recursive Function
Statements
True
Condition
False
Remaining Statements
Program
#include<stdio.h>
Each call gets its own copy of count
fun ( int count )
{
printf( "%d\n", count );
fun ( count + 1 );
}
int main()
{
Calling function in main
fun ( 1 );
return 0;
}
Library Functions in C Programming
Standard library functions are inbuilt functions
in C programming language
Library functions
Predefined
Example: #include<stdio.h>
List of Most Used Header Files In C language
Header File Description
stdio.h This is standard input/output header file
in which Input/Output functions are
declared
All string related functions are defined
string.h
in this header file
math.h All maths related functions are defined
in this header file
time.h This header file contains time and clock
related functions
ctype.h All character handling functions are
defined in this header file
Header File <stdio.h>
User-friendly syntax
Advantages of using C Library Functions
User-friendly syntax
Advantages of using C Library Functions
User-friendly syntax
Advantages of using C Library Functions
User-friendly syntax
Program : - Using math.h
#include <stdio.h>
#include <math.h>
int main()
{
float num, root;
printf("Enter a number: ");
scanf("%f", &num);
root = sqrt(num);
printf("Square root of %f = %f", num, root);
return 0;
}
Array in C
datatype name_of_array[size];
• Datatype
• Name of array
• Size (integer)
Array Initializing and Memory Representation
of an Array
int arr[5]={ 10,11,12,13,14};
Access Array Elements
• Array elements access by indices.
Arrays
One Multi
dimensional dimensional
array array
Type of Array
• One dimensional Array
int a[5];
• Multi-dimensional Array
int m[3][3];
Program
#include <stdio.h>
int main()
int arr[5]={10,11,12,13,14};
for(int i=0;i<=4;i++)
printf("%d\n",arr[i]);
return 0;
}
Two Dimensional Array in C
• Datatype
• Name of array
• rows (integer)
• columns (integer)
• Number of elements in 2D arrays is multiply of rows and columns for eg. Int
x[3][3] has 3*3 i.e. 9 elements.
Array Initializing and Memory Representation
of an Array
int x[3][4] = {{1,2,3}, {4,5,6}, {7,8,9}};
• 2D Arrays represent multiple data items of the same type in the form
of matrix.
25 30 15 12 16
12 15 16 25 30
Types of sorting
• Selection sort
Types of sorting
• Selection sort
• Insertion sort
Types of sorting
• Selection sort
• Insertion sort
• Bubble sort
Types of sorting
• Selection sort
• Insertion sort
• Bubble sort
• Merge Sort
Types of sorting
• Selection sort
• Insertion sort
• Bubble sort
• Merge Sort
• Quick sort
Types of sorting
• Selection sort
• Insertion sort
• Bubble sort
• Merge Sort
• Quick sort
• Heap sort
Selection sort
• Selection Sort finds the smallest element in the array and exchanges it
with the element in the first position, it then finds the second
smallest element and exchanges it with the element in the second
position and continues this process until the entire list is sorted.
Selection sort
• 22 10 15 18 >> 10 22 15 18
• 10 22 15 18 >> 10 15 22 18
• 10 15 22 18 >> 10 15 18 22
10 15 18 22
Insertion sort
• Insertion sort, start with one item, take a new item and sort the two
items relative to each other, then take a new item and sort the three
items relative to each other (swapping the new item with consecutive
values until it is no longer lower, and thus inserting it in that position),
and so on
Bubble sort
• Bubble sort, swap neighbours the larger items drop down while the
smaller ones bubble up, in n-1 passes through the array.
• 6 4 2 >> 462
• 4 6 2 >> 426
• 4 2 6 >> 246
Merge sort
• Merge Sort follows the Divide and Conquer rule where in it divides
the input array into two halves, sorts the two halves and merges the
two sorted halves.
Searching
• Binary Search
• Linear Search
linear search
search element: 10
15 18 22 35 10 45 53
Binary search
• In a binary search, the data in the array is ordered and then the
middle of the contracted array is tested until the required match is
found
Character Array
• Character array is collection of characters, stored under a
single name.
Character Array
• Character array is collection of characters, stored under a
single name.
Data type
name of character
array
String
Initializing Character Array
char a[]=“Program”;
• “Program” is a string.
output