×

Use of a Function Prototype

A function is a collection of statements that work together to complete a task. To define any function in the program, firstly, we have to define the function prototype. The function prototype term is defined here.   

What is Function Prototype?

The function prototype is also known as the function interface. A function prototype is just a function's declaration, which includes the function's name, parameters, and return type. A function prototype informs the compiler that the function might be utilized later in the program.

Syntax of Function Prototype:

returnTypefunctionName (datatype argument1, datatype argument2, datatype argument3 ...);

The Components of a Function Prototype

1. Return types

A function might be returned a value. The data type of the value that the function returns are known as the return type.

Example 1:

#include <stdio.h>
float add (float num1, float num2); // Function prototype
int main ()
{  
 	float result = add (2.8, 6.9);
  	printf("The addition is %f ", result);
 	return 0;
}
float add (float num1, float num2)
{
  	float num3;
  	num3 = num1 + num2;
  	return num3;
}

Output:

The addition is 9.700000

Explanation:

This is the program for adding the two float values using a function. This program adds two float values and returns the result. Here, we are returning the float value; that's why the function return type also floats. As we are adding two float values, its addition is also a float value. Based on the return data, the return type can be int, float, Boolean, character, double, string, and void. When the function does not have any value, that time function data type is void.

See the following example to understand the void return type.

Example 2:

#include <stdio.h>
void printName (char name[20]);
int main() 
{
 char data[20]="JavaTPoint";
  	printName (data);
  	return 0;
}
void printName (char name[20])
{
  	printf("The name is : %s ", name);
}

Output:

The name is: JavaTPoint

Function printName does not return any value; that's why its return type is void.

2. List of arguments

It indicates the number of variables with their data type passed to the function.

For Example:

  • void sample ();

This function has 0 arguments.

  • void sample (int num1, int num2);

This function has two arguments which having the same datatypes.

  • void sample (float num1, int num2, char word);

This function has three arguments, one variable of float data type, another variable is of int datatype, and the third one is of char data type.

3. Function name

The function name is the name given to the function.

For example:

void studentData ();

The studentData is the name of the function.

What is Function Definition?

The function definition includes the function name, return type, and parameters with the function body. The function implementation is included in the function definition.

Syntax:

returnTypefunctionName (Datatype argument1, datatype argument2, datatype argument3 ...)
{
function body
}

Example:

#include <stdio.h>
float subtraction (float num1, float num2);
int main ()
{  
   	float sub; 
   	sub= subtraction (9.8,1.1);
   	printf("The subtraction is %f", sub);
   	return 0;
}
float subtraction (float num1, float num2)
{
// function body
   	float num3;
   	num3 = num1 - num2;
   	return num3;
}

Output:

The subtraction is 8.700000

In the above program, the lines present inside the '{ }' of the subtraction function is called the body of the subtraction function.

Difference between a Function Definition and a Function Prototype

Function PrototypeFunction Definition
It includes a declaration of the function.It has the body of the function.
It always ends with a semicolon.There is no semicolon at the end.
It includes the function's name, parameters, and return type.It includes the function name, return type, parameters, and the function body.
A function prototype informs the compiler that the function might be utilized later in the program.It includes the code that specifies the purpose of the function.
Syntax:
returnTypefunctionName (Datatype argument1, datatype argument2, datatype argument3 ...);  
Syntax:
returnTypefunctionName (Datatype argument1, datatype argument2, datatype argument3 ...)
{
function body
}
Example:
int add( int num1, int num2);  
Example:
int add(int num1, int num2)
{
int num3; num3= num1 + num2; return num3;
}

Use of Function Prototype

  1. It indicates how many arguments are passed to the function.
  2. It specifies the return type for the function.
  3. It provides information about the data types of each argument that has been passed.
  4. It indicates the order in which the function's parameters are passed.
  5. It does not have a functioning body.

Related Topics

List of Finance Ministers of India

Finance, in layman's terms, is defined as the administration of money, debt, investment, or banking by any government or commercial institution. It requires overseeing the acquisition of required money. Importance of...

14 minutes read.

Top Free Online IDE Compilers in 2024

IDE is an abbreviation for an Integrated Development Environment. An integrated development environment (IDE) is a software tool that offers computer programmers many features for developing applications. An IDE usually...

3 minutes read.

Top 5 Places to Practice Ethical Hacking

Practice is necessary to make our skills updated and up to date. Since it's more about how you utilize the tools you know than how many you know. Hacking is...

3 minutes read.

List of States and Union Territories in India

Introduction India is the World's second most populous country and the "7th largest" country overall. Twenty-eight states and eight union territories make India's union of states. India is a union of...

13 minutes read.

Frontend vs Backend

The two most frequently used terms in web development or any software development are frontend and backend. What is Frontend? The frontend of a website refers to the area where users interact...

4 minutes read.

List of Phobias

Introduction Everyone has some fear in their life, but it may be changed into a disease when this Fear crosses the limit. These Diseases are known as Phobias. Sometimes it happens...

7 minutes read.

8 Technical Courses to Get a Job in IT

Technical jobs are among the highest-paying careers available today. Most IT, software, and electronics engineers hope to land a job like this. Each year, more than 1.5 million engineers graduate...

3 minutes read.

Tourist Places in Kerala

Kerala is also referred to as God's own country, and it is a surreal destination where morning brings in the magic and mist. The beauty of Kerala appeals to everyone,...

8 minutes read.

Tourist Places in Rameshwaram

Rameshwaram, a Hindu pilgrimage destination in the Indian state of Tamil Nadu, is a must-visit. Because of its connection to the Great Ramayana, this town, located in the far south...

6 minutes read.

Types of Web Browsers

What is a Web Browser? The application software used to access the internet facilities provided by World Wide Web (WWW) is called a Web Browser. When a user wants information from the...

4 minutes read.

What are the Baud Rate and its Importance?

Computers communicate by sending digital data bits via transmission media from one device to another. You don't need to worry about setting up the specifics to send and receive data....

3 minutes read.

6 Essential Mobile Apps for Computer Science

Today, there is just one solution for every single job, including exchanging data, viewing movies, ordering a cab, and many more and that solution is our Smartphone. All of these...

4 minutes read.

List of NITs in India

NIT - RESOURCES TO INCREASE EDUCATIONAL CALIBRE These institutions are leading engineering institutes in India administered under the ministry of education; they are declared as institutions of national importance. They are...

11 minutes read.

List of Home Ministers of India

Introduction Home Minister is a very valuable post for India. The person who sits on the chair of the home ministry will decide India's inner security. The first home minister of...

8 minutes read.

List of Fruits and Vegetables

We eat fruits and vegetables on a regular basis in our daily lives. It is a central aspect of our existence. Fruits are juicy fleshy plant products that include seeds,...

10 minutes read.

List of Birds

Introduction There are many creatures present on our earth. Each creature has its value. The presence of these creatures makes our earth a really beautiful planet to live on. But here...

5 minutes read.

List of Ayurvedic Treatments

Basti The mother of all therapies, Basti, is revered. According to Wikipedia, "Basti is one of the main pradhana karmas of Panchkarma, and it is Used to treat Vata disorders." We...

12 minutes read.

Introduction of Basic Service Set (BSS)

Basic Service Sets (BSS) The fundamental component of an IEEE 802.11 LAN is the BSS. Each BSS region essentially correlates to a certain number of stations' coverage. The idea behind a...

2 minutes read.

List of Cricket World Cup Winners

Introduction Cricket is one of the games, the craze of which is unbeatable. Love for cricket can be seen amongst children, teenagers and even adults. The craziness and love are not...

9 minutes read.

List of Professions

Introduction Are you looking for the best jobs in India? Many students have this problem when they finish school. Today, we'll discuss some of the highest-paying careers available. Everyone wants to make...

14 minutes read.