CSC 183 Chap-10
CSC 183 Chap-10
Example
int max(int a, int b); int max(int a, int b){
return a>b?a:b;
void main(){ }
int x;
x = max(5,8);
x = max(x,7);
}
Void main()
{
Int a, b=8,c=4;//global variable
c=a+b;
Printf(“%d”,c)
}
Void main()
{
char dept[5] = “CSE”; //global variable to declare a string
//functions
int csc183_A() {}
int csc183_B() {}
int csc183_C() {}
int csc183_D() {}
Function Definition:
return_type function_name (type1 name1, type2 name2,
...,typen namen)
{
....statements...
}
The parameters
Some Examples
Function Prototype Examples
double squared (double number);
void print_report (int);
int get _menu_choice (void);
Function Definition Examples void parameter list means
double squared (double number) it takes no parameters
{
return (number * number);
}
int main()
{
int n1,n2,sum;
printf("sum = %d",sum);
return 0;
}
return <expression>;
void checkPrimeNumber();
int main()
{
checkPrimeNumber(); // no argument is passed to prime()
return 0;
}
// return type of the function is void becuase no value is returned from the function
void checkPrimeNumber()
{
int n, i, flag=0;
int main()
{
int n, i, flag = 0;
if (flag == 1)
printf("%d is not a prime number.", n);
else
printf("%d is a prime number.", n);
return 0;
}
int main()
{
int n;
return 0;
}
if(flag==1)
printf("%d is not a prime number",n);
else
printf("%d is a prime number",n);
return 0;
}