Introduction To DS - MCH
Introduction To DS - MCH
Introduction To DS - MCH
STRUCTURES
x=&a[0];
x=??
x=a;
x=??
x+1=??
*x=??
*(x+1)=??
FUNCTIONS
Program often broken up into segments known as
functions.
Takes in inputs, processes it, and then outputs the
result.
Three intrinsic features of functions:
Function Call: A function f may use the output from
another function, g. f is the calling function, g is the
called function.
Function Declaration/Prototype: Identifies a function
with its name, the data types of the arguments passed
and the data type of the output.
Function Definition: Body of the function containing the
executable code for that function.
AN EXAMPLE (IN C)
#include<stdio.h>
int sum_digit(int number); //function prototype
main()
{
int p, s;
scanf(“%d”,&p);
s=sum_digits(p); //function call
printf(“Sum of digits of %d is %d\n”, p, s);
}
int sum_digits(int n) //function definition
{
int sum=0, digit;
if(n<0) n=-n;
while(n!=0)
{
digit=n%10;
sum +=digit;
n=n/10;
}
return sum;
}
POINTERS AND FUNCTIONS