What is function in C programming?

Definition of function:

Function is block or part of program. When any program is very long or same code is repeating many times then we try to cut the program in different parts (or blocks) so that whole program became more understandable, easier to debug (error checking) and size of code will be lesser.

Syntax of function in c programming

Simple example of function structure

int sum (int,int); //function declaration
int main(){
int p;
p=sum(3,4); //function call
return 0;
int sum( int a,int b){ //function definition
int s; //function body
return s; //function returning a value

Detail explanation of syntax of function

(1) Function_name :

Function naming rule in c programming:

Rule 1. Name of function includes alphabets, digit and underscore.
Valid name: world, addition23, sum_of_number etc.
Invalid name: factorial#, avg value, display*number etc.
More example click here

Rule 2. First character of name of any function must be either alphabets or underscore.
Valid name: _calulate, _5,a_, __ etc.
Invalid name: 5_, 10_function, 123 etc.
More example click here

Rule 3. Name of function cannot be any keyword of c program.
Invalid name: interrupt, float, asm, enum etc.
More example click here

Rule 4. Name of function cannot be global
Valid name: __TOTAL__, __NAME__ ,__TINY__etc.
Invalid name: __TIME__,__DATE__, __FILE__,__LINE__,__STDC__
More example click here

Note: It is good practice to not write the variable name in the above format.

Rule 5: Name of function cannot be register Pseudo variables

Register Pseudo variables are:

For examples click here.

Rule 6. 
Name of function cannot be exactly same as of name of other function or identifier within the scope of the function.

Good example click here

Rule 7. Name of function is case sensitive.

Rule 8. Only first 32 characters are significant of the function’s name.
All three function name are same because only first 32 characters has meaning. Rest has not any importance.


dinhpq said...

Thank you so much.

Mahesh Vanol said...

thanks a lot...

Santosh said...


Elango said...

elango said

very useful for beginers

Purushottam Shah said...


Anonymous said...

I wish I had seen these tutorials during my first semester. This guy is so good. much better than my former professor. Thanks for this. I hope you are a professor in a University somewhere. God bless you more.

Anonymous said...

In the example.. while u return the sum of 3 and 4 and storing it in p, u should use p in printf statemen..
i.e., printf(“%d”,p);
instead of printf(“%d”,sum);

balikuddembe christopher said...

hullo, i need to write a programme that outputs an arithmetic calculator. please help.