• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » C++ » Functions » What is Function Declarations or Function Prototype?
Next →
← Prev

What is Function Declarations or Function Prototype?

By Dinesh Thakur

Like variables, functions also need to be declared before they are used in programs. A function declaration is also known as function prototype. Function prototype is a model or a blueprint for a function that informs the C++ compiler about the return type, the function name, and the number and data type of the arguments passed to the function. Function name together with parameter list is known as function signature and it does not include return type of a function. The syntax for declaring a function is

return_type function_name(parameter_list);

where,

return_type = the data type of the value returned by the function(by default, it is int)

function_name = the name of the function

(parameter_list) = the list ofvariab1es along with their data types

The syntax for specifying a function’s parameter list is

typel param1, type2 param2, … , typeN paramN

where,

type1 type2, typeN = data types of parameters – cannot be void

paraml, param2, … , paramN = list of variables (also known as parameters)

To understand the concept of function declaration, consider this statement.

int func(int x, char y);

In this statement, a function named funds declared which returns an integer value and takes an integer and a character value as parameters: Note that in function prototype, data types of parameters must be specified, however, specifying parameter names is optional. This is because the compiler only needs to be aware of the data type of every parameter. Thus, the prototype of func can also be written as

int func(int, char);

These arguments are known as fixed arguments and are type checked at compile time.

The function whose parameter_list is empty or void can be declared as

void disp () ;

It can also be written as

void disp (void) ;

Function prototype enables the compiler to validate a function call. Whenever a function is called, the compiler checks whether the return type, the function name, and the type and order of parameters are compatible with the function declaration or not. In case a conflict arises, an error is raised. In addition, function prototype forces the conversion of arguments to the appropriate type. For example, the sqrt function of header cmath specifies a double argument in its function prototype. However, this function can also be called with an int argument and the function will work correctly because of this implicit conversion.

To understand the concept of implicit type conversion of arguments, consider this statement.

cout<<sqrt(4) ;

This statement prints the value 2 as the function prototype will force the compiler to convert integer argument (4)to double argument (4. 0)and then double argument (4. 0) will be passed to sqrt.

Open Parameter List: Generally, a function accepts a fixed number of parameters. However, C++ also enables to provide variable or open number of parameters in parameter list. Such functions must have at least one fixed argument. If this mandatory argument is not provided, the other arguments in the list cannot be accessed. The last argument of this function should be ellipsis(…), which indicates that the function may take any number of arguments after the mandatory argument.

To understand the concept of open parameter list, consider this statement.

int myfunc (int count, long total, ... );

In this statement, count and total are the fixed arguments that must be passed whenever the function is called. However, the variable arguments specified by ellipsis(…) may or may not be passed. Note that the variable arguments are passed with no type checking.

You’ll also like:

  1. Function Declaration or Prototype in C
  2. JavaScript Prototype
  3. Write a C++ program for prototype constructors.
  4. Write A C++ Program To Add, Subtract And Multiply Two Numbers By Using The Function Within Function Concept (Nesting Of Function).
  5. Write A C++ Program To Find The Sum Of: 1! /5+ 2! /4+ 3! /3+ 4! /2+ 5! /1 Without Using Function (Except Main Function). Where! Symbol Indicates Factorial Of Any Number.
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

C++ Tutorials

C++ Tutorials

  • C++ - Data Types
  • C++ - Operators Types
  • C++ - CPP Program Structure
  • C++ - Conditional Statements
  • C++ - Loop
  • C++ - do-While Loop
  • C++ - Control Statements
  • C++ - Tokens
  • C++ - Jump Statements
  • C++ - Expressions
  • C++ - Constants
  • C++ - Character Set
  • C++ - Iteration Statements
  • C++ - I/O Statements
  • C++ - String
  • C++ - Manipulators

C++ Operator

  • C++ - Input/Output Operator
  • C++ - Operator Overloading

C++ Functions

  • C++ - Functions
  • C++ - Member Functions
  • C++ - Returning Object from Function
  • C++ - Call by Value Vs Reference
  • C++ - Friend Function
  • C++ - Virtual Function
  • C++ - Inline Function
  • C++ - Static Data Members
  • C++ - Static Member Functions

C++ Array & Pointer

  • C++ - Array
  • C++ - Array of Objects
  • C++ - Arrays as Class Members
  • C++ - Vector
  • C++ - Pointer
  • C++ - 'this' Pointer

C++ Classes & Objects

  • C++ - Class
  • C++ - Program Structure With Classes
  • C++ - OOP’s
  • C++ - Objects as Function Arguments
  • C++ - Procedure Vs OOL
  • C++ - Object Vs Class
  • C++ - Creating Objects
  • C++ - Constructors
  • C++ - Copy Constructor
  • C++ - Constructor Overloading
  • C++ - Destructor
  • C++ - Polymorphism
  • C++ - Virtual Base Class
  • C++ - Encapsulation

C++ Inheritance

  • C++ - Inheritance
  • C++ - Multiple Inheritance
  • C++ - Hybrid Inheritance
  • C++ - Abstraction
  • C++ - Overloading

C++ Exception Handling

  • C++ - Exception Handling
  • C++ - Templates
  • C++ - Standard Template Library

C++ Data Structure

  • C++ - Link List

C++ Programs

  • C++ Program for Electricity Bill
  • C++ Program for Multiply Matrices
  • C++ Program for Arithmetic Operators
  • C++ Program For Matrices
  • C++ Program for Constructor
  • C++ Program Verify Number
  • C++ Program Array Of Structure
  • C++ Program to find Average Marks
  • C++ Program Add And Subtract Matrices
  • C++ Program Menu Driven
  • C++ Program To Simple Interest
  • C++ Program To Find Average
  • C++ program exit()
  • C++ Program Using Array Of Objects
  • C++ Program Private Member Function
  • C++ Program To Reverse A String
  • C++ Program to Operator Overloading

Other Links

  • C++ - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW