EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Function Prototype in C

Home » Software Development » Software Development Tutorials » C Programming Tutorial » Function Prototype in C

Function Prototype in C

Introduction to Function Prototype in C

A function prototype is one of the most important features of C programming which was originated from C++. A function prototype is a declaration in the code that instructs the compiler about the data type of the function, arguments and parameter list. As we all know that a block of code which performs a specific task is called as a function. In the same way, a function prototype is a function which specifies return type, function name and its parameter to the compiler so that it can match with the given function calls when required.

Syntax:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

returntypefunctionname( datatype paramter1 , datatype paramter2 , datatype paramter3..);

Example:

Code:

intaddition(int a, int b);

In the above example addition is the name of the function of integer data type is the return type and a and b are the argument of two arguments of type int passed to the function. Note that we can pass as many arguments we want in our function based on the requirement. Also in the same program we can define as many prototype we want but they should differ in either name or argument list. All you have to do is define a prototype in the code and then call it anytime by using the function name.

Examples of Function Prototype in C

Given below are the examples mentioned:

Example #1

Code:

#include <stdio.h>
intNum_addition( inti , int j );// prototype for the function
intmain()
{
int num1,num2,total;
printf( " Please enters the 2 numbers you want to add : " ) ;
scanf( "%d %d" , &num1 , &num2 ) ;
total = Num_addition( num1 , num2 ) ;        // calling the function
printf( " The total of the given numbers is = %d " , total ) ;
return 0 ;
}
intNum_addition( inti , int j )         // function definition  for prototype
{
intresults
results = i + j ;
return results ;
}

Output:

function prototype in c 1

As you can see in the above code, initially we are declaring the function prototype for the addition of two numbers with name “ Num_addition ” of integer return type with two integer arguments named as i and j into the function. In the main class, we defined three integers num1, num2, and total. After that, we are taking input from the users then storing the addition results of the two given numbers in total. To call the function “ Num_addition“ function is used again. At last in the function definition you can see we are giving the logic to perform addition and store it in results.

Example #2

Code:

#include <stdio.h>
intNum_subtraction( inti , int j ); // prototype for the function
intmain()
{
int num1 , num2 , output ;
printf( " Please enters the 2 numbers you want to subtract : " ) ;
scanf( "%d %d" , &num1 , &num2 ) ;
output = Num_subtraction( num1 , num2 ) ;
printf( " The subtraction of the given numbers is = %d " , output ) ;
return 0 ;
}
intNum_subtraction( inti , int j )// function definition
{
intresults ;
results = i - j ;
return results ;
}

Output:

subtraction of the given number

As you can see in the above code, initially we are declaring the function prototype for the subtraction of two numbers with name “ Num_subtraction ” of integer return type with two integer arguments named as i and j into the function. In the main class, we defined three integers num1, num2, and output. After that, we are taking input from the users then storing the subtraction results of the two given numbers in output. To call the function Num_subtraction function is used again. At last in the function definition you can see we are giving the logic to perform subtraction and store it in results.

Popular Course in this category
C Programming Training (3 Courses, 5 Project)3 Online Courses | 5 Hands-on Projects | 34+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,617 ratings)
Course Price

View Course

Related Courses
C++ Training (4 Courses, 5 Projects, 4 Quizzes)Java Training (40 Courses, 29 Projects, 4 Quizzes)

Example #3

Code:

#include <stdio.h>
intNum_multiplication( inti , int j );// prototype for the function
intmain()
{
int num1 , num2 , output ;
printf( " Please enters the 2 numbers you want to multiply : " );
scanf( "%d %d" , &num1 , &num2 ) ;
output = Num_multiplication( num1 , num2 );// calling the function
printf( " The multiplication of the given numbers is = %d " , output );
return 0 ;
}
intNum_multiplication( inti , int j )// function definition
{
intresults ;
results = i * j ;
return results ;// return statement to return results to user
}

Output:

function prototype in c 3

As you can see in the above code, initially we are declaring the function prototype for the multiplication of two numbers with name “ Num_multiplication ” of integer return type with two integer arguments named as i and j into the function. In the main class, we defined three integers num1, num2, and output. After that, we are taking input from the users then storing the multiplication results of the two given numbers in output. To call the function Num_multiplication function is used again. At last in the function definition you can see we are giving the logic to perform multiplication and store it in results.

Conclusion

Defining a function prototype in C helps is saving a huge amount of time in debugging and when it comes to overloading the function, prototypes help in figuring out which function to call in the given code which is really helpful in avoiding ambiguity and other programming problems.

Recommended Articles

This is a guide to Function Prototype in C. Here we discuss the introduction to Function Prototype in C along with respective examples for better understanding. You may also have a look at the following articles to learn more –

  1. C Literals
  2. Memory Allocation in C
  3. File Handling in C
  4. Constants in C

All in One Software Development Bundle (600+ Courses, 50+ projects)

600+ Online Courses

50+ projects

3000+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
C Programming Tutorial
  • Function
    • Math Functions in C
    • Hashing Function in C
    • Recursive Function in C
    • Power Function in C
    • fputs in C
    • C puts() Function
    • fprintf() in C
    • fseek() in C
    • Stderr in C
    • ASCII Value in C
    • strcat() in C
    • Inline Function in C
    • sizeof() in C
    • Function Prototype in C
    • C ftell()
  • Basic
    • Introduction to C
    • What is C
    • Career in C Programming
    • Advantages of C
    • How to Install C
    • Best C Compilers
    • Data Types in C
    • Variables in C
    • C Keywords
    • C Command
    • Command Line Arguments in C
    • C Literals
    • Constants in C
    • Unsigned Int in C
    • String in C
  • Pointers
    • Pointers in C
    • Null pointer in C
    • Function Pointer in C
    • Double Pointer in C
    • Void Pointer in C
    • Const Pointer in C
    • Dangling Pointers in C
    • Pointer Arithmetic in C
  • Operators
    • C Operators
    • Arithmetic Operators in C
    • Relational Operators in C
    • Assignment Operators in C
    • Logical Operators in C
    • Conditional Operator in C
    • Modulus Operator in C
    • Ternary Operator in C
    • Address Operator in C
    • Unary Operator in C
    • Operators Precedence in C
    • Left Shift Operator in C
  • Control Statement
    • Control Statements in C
    • If Statement in C
    • If-else Statement in C
    • Else if Statement in C
    • Nested if Statement in C
    • #else in C
    • Structure Padding in C
    • Nested Structure in C
    • Continue Statement in C
    • Break Statement in C
    • Switch Statement in C
    • Goto Statement in C
  • Loops
    • Loops in C
    • For Loop in C
    • While Loop in C
    • Do While Loop in C
    • Nested Loop in C
    • Infinite Loop in C 
  • Array
    • Arrays in C Programming
    • 2-D Arrays in C
    • 3D Arrays in C
    • Multidimensional Array in C
    • Array Functions in C
    • Strings Array in C
  • Sorting
    • Sorting in C
    • Heap Sort in C
  • Advanced
    • Constructor in C
    • Encapsulation in C
    • C Storage Classes
    • Static Keyword in C
    • File Handling in C
    • Queue in C
    • Hexadecimal in C 
    • typedef in C
    • Memory Allocation in C
    • Linked List in C
    • Volatile in C
    • Tokens in C
    • Expression in C
    • Regular Expression in C
    • Error Handling in C
    • Types of Errors in C
    • Preprocessor in C
    • Preprocessor Directives in C
    • fscanf() in C
    • #Pragma in C
    • #ifndef in C
    • #undef in C
    • Macros in C
  • C programs
    • Patterns in C Programming
    • Star Patterns in C
    • Number Patterns in C
    • Swapping in C
    • Reverse Number in C
    • Palindrome in C Program
    • Factorial in C
    • Fibonacci Series in C
    • Square Root in C
    • Random Number Generator in C
    • Prime Numbers in C
    • Escape Sequence in C
    • Reverse String in C
    • Leap Year Program in C
    • Anagram Program in C
    • Strong Number in C
    • String Concatenation in C
    • C Programming Matrix Multiplication
    • Decimal to Octal in C
    • Expression Evaluation in C
    • Decimal to Hexadecimal in C
  • Interview question
    • C Programming Interview Questions

Related Courses

C Programming Training Course

C++ Training Course

Java Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - C Programming Training Course Learn More