×

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 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 Chinese Products in India

Government can measure the growth and development best by evaluating its GDP(Gross Domestic Product). Gross Domestic Product or GDP provides us with a value of the total goods and services...

5 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.

List of IT Companies in India

Information technology is currently the most well-known industry in the world. It has the power to make users' thoughts come true. IT firms are companies that provide information technology services....

5 minutes read.

Top Product Based Companies in Chennai

Let's first learn what product-based companies actually are. As the name suggests, a product-based company makes products for consumers at different levels and markets. A service-based company, on the other...

4 minutes read.

List of Presidents in India

Introduction After years of colonized British control, our country was eventually able to break free in 1947. The year of independence, 1947, was when the entire country came together into a...

5 minutes read.

Best Tech Movies That Every Programmer Must Watch

Every person lives their life as if it was a movie, and every programmer enjoys viewing their work lives through the lens of films. Hollywood, as we all know, is...

4 minutes read.

List of Online Shopping Sites in India

Introduction The old days are gone when we used to go to the market to purchase every little thing. Now, most of the shopping is done online through various digital platforms....

6 minutes read.

How to become a software engineer

Software developers, also known as software engineers, develop innovative software for clients and businesses. From a personal banking app to a business project management workflow system, many of the essential...

3 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.

Blood Plasma

Blood is made up of plasma, a yellow liquid substance. It supports the body's pH balance, blood volume, blood pressure, immunity, coagulation, and other physiological functions. Furthermore, it is essential...

4 minutes read.

5 Best Books for Competitive Programming

Competitive programming aims to beat other programmers in every aspect, just like in sports. So, it's not enough to solve a problem; you also need to do so in the...

4 minutes read.

List of South American Countries

South America got its name because it encompasses the whole southern portion of the supercontinent of the Americas. The Pacific Ocean encircles it on its western side, the Atlantic Ocean...

8 minutes read.

What is Competitive Programming?

Competitive programming is a technique that makes you a master in coding. Competitive programming provides some advantages. These advantages are as follows: It helps us in getting a job. It also improves...

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.

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 Colleges in Bengaluru

1. Symbiosis Institute of Business Management SIBM, Bengaluru The Bengaluru-based Symbiosis Institute of Business Management has been working to provide top-quality management education ever since it opened its doors in 2008....

19 minutes read.

Explain dobereiner's triad

Dobereiner's Law of Triads with Example There have been several attempts since the beginning of time to organize the elements according to their qualities. Many theories to categorize the elements emerged...

4 minutes read.

Top 7 programming languages for backend web development

Web Development is primarily divided into two facets: front-end and back-end development. They each have their own set of technology and tools. For instance, when discussing front-end development, HTML, CSS,...

4 minutes read.

Largest State of India

There are twenty-eight states and eight union territories in India. Each of these states and territories has its geographical location and population. In this article, we are going to look...

4 minutes read.