A function is a block of program code which deals with a specific task. Making functions is a way of isolating one block of code from other independent blocks of code.
Syntax:
return-type function-name (parameter-list);
Example :
int sum(int a, int b); // <-- Function prototype declaration
Syntax:
return-type function-name (parameter-list)
{
// block of code
return value ;
}
Example:
int sum(int a, int b)
{
int c = a+b;
return c;
}
Syntax:
function-name(parameter-list);
Example:
int main()
{
sum(10,20); // <-- function call
return 0;
}
Note: When calling any function , function declartion or function definition must be done before it.
int sum(int a, int b); //<-- function declaration
// Function definition
int sum(int a, int b)
{
return (a+b);
}
int main()
{
int c = sum(10,20); // <-- function call
printf("%d\n", c);
return 0;
}
← Previous
Next →
© 2018 BreakInerview