Miscellaneous

List of Countries and Capitals List of Chinese Apps banned by India List of Chinese Products in India List of Presidents in India List Of Pandemics List of Union Territories of India List of NITs in India List of Fruits List of Input Devices List of Insurance Companies in India List of Fruits and Vegetables List of IIMs in India List of Finance Ministers of India List of Popular English Songs List of Professions List of Birds List of Home Ministers of India List of Ayurvedic Treatments List of Antibiotics List of Cities in Canada List of South Indian Actress Pyramid of Biomass Axios Cleanest City in India Depression in Children Benfits of LMS for School Teachers First Gold Mine of India National Parks in India Highest Waterfall In India How Many States in India Largest Museum in India Largest State of India The Longest River in India Tourist Places in Kerala List of Phobias Tourist Places in Rameshwaram List of Cricket World Cup Winners List of Flowers List of Food Items Top 15 Popular Data Warehouse Tools YouTube Alternatives 5 Best Books for Competitive Programming Tourist Places in Tripura Frontend vs Backend Top 7 programming languages for backend web development Top 10 IDEs for Programmers Top 5 Places to Practice Ethical Hacking Pipelining in ARM Basics of Animation Prevention is Better Than Cure Essay Sharding Tourist Places in Uttrakhand Top Best Coding Challenge Websites 10 Best Microsoft Edge Extensions That You Can Consider Best Tech Movies That Every Programmer Must Watch Blood Plasma What are the effects of Acid Rain on Taj Mahal Programming hub App Feedback Control system and Feedforward Functional Programming Paradigm Fuzzy Logic Control System What is Competitive Programming Tourist places in Maharashtra Best Backend Programming Languages Best Programming Languages for Beginners Database Sharding System Design DDR-RAM Full Form and its Advantages Examples of Biodegradables Waste Explain dobereiner's triad Financial Statements with Adjustments How to Get Started with Bug Bounty Interesting Facts about Computers Top Free Online IDE Compilers in 2022 What are the Baud Rate and its Importance The Power Arrangement System in India Best Backend Programming Languages Features of Federalism Implementation of Stack Using Array List of IT Companies in India Models of Security Properties of Fourier Transform Top 5 Mobile Operating Systems Use of a Function Prototype Best Examples of Backend Technologies How to Improve Logics in Coding List of South American Countries List of Sports List of States and Union Territories in India List of Universities in Canada Top Product Based Companies in Chennai Types of Web Browsers What is 3D Internet What is Online Payment Gateway API Bluetooth Hacking Tools D3 Dashboard Examples Bash for DevOps Top Platform Independent Languages Convert a Number to Base-10 Docker Compose Nginx How to find a job after long gap without any work experience Intradomain and Interdomain Routing Preparation Guide for TCS Ninja Recruitment SDE-1 Role at Amazon Ways to Get into Amazon Bluetooth Hacking Tools D3 Dashboard Examples Bash for DevOps Top Platform Independent Languages Convert a Number to Base-10 Docker Compose Nginx How to find a job after long gap without any work experience Intradomain and Interdomain Routing Preparation Guide for TCS Ninja Recruitment SDE-1 Role at Amazon Ways to Get into Amazon 7 Tips to Improve Logic Building Skills in Programming Anomalies in Database Ansible EC2 Create Instance API Testing Tutorial Define Docker Compose Nginx How to Bag a PPO During an Internship How to Get a Job in Product-Based Company Myth Debunked College Placements, CGPA, and More Programming Styles and Tools What are Placement Assessment Tests, and How are they Beneficial What is Ansible Handlers What is Connectionless Socket Programming Google Cloud Instances Accounts Receivable in SAP FI FIFO Page Replacement Algorithm IQOO meaning Use of Semicolon in Programming Languages Web Development the Future and it's Scope D3 Dashboard with Examples Detect Multi Scale Document Type and Number Range in SAP FICO BEST Crypto Arbitrage Bots for Trading Bitcoin Best FREE Audio (Music) Editing Software for PC in 2023 Best FREE Second Phone Number Apps (2023) Characteristics of Speed What Is Console Log? Higher Order Functions and Currying Amazon Alexa Hackathon Experience Social Network API Data Compression Techniques Introduction to Vault

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.