Functions in C

Definition :

  • A function is a block where program code is written.
  • A function is set of instruction which is put together to perform a specific task.
  • A function is a subroutine design for doing one job/task.

There are two types of functions present in C- programming:

  1. Pre-defined (compiler supported function).
  2. User-defined functions.

Working :

Untitled Diagram (17).jpg

Pre-defined function:

  • For pre-defined function, the declaration is present in a Header file.
  • All the pre-defined function definition are present in a Library.
  • And the function is present in our program.

User-defined :

  • If you define function above the main function, then there’s no need to define it or declare it.

Syntax :

prototype; //declaring a function above the main()
main()
{
      statements;
      //calling a function within the main
}
define;       // defination of a Function below the main()

There are four different ways to declare/write a function-

Syntax :

return_type function_name(arguments);

 

1. Void function_name(void) :

  • This function neither returns anything nor takes anything.

2. Void function_name(argument) :

  • This function is takes arguments but does not returns any.

3. returntype function_name(void) :

  • This function takes nothing but returns int/char/bool/float.

4. returntype function_name(argument) :

  • This function returns values and takes arguments which we’ve passed from main function.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: