Same data types and count but signature different – Computer Sir Ki Class


Lost your password?

Don't have an account ?
Register (It's FREE) ×


Code Learning #CPP#4487    siteicon   siteicon  

Same data types and count but signature different

Function overloading when function data types are same, count is also same but signature is different.

Learning Objectives

  • Understanding overloading with same type and count of parameter with different signature due to different order of parameters.

Source Code

TC++ #4487


Source Code

Run Output

Output from char c, int n
Output from int n, char c

Code Understanding

void action(char c,int n) {
cout<<“Output from char c, int n”<<endl;
for(int i=0;i<n;i++) cout<<c;
cout<<endl; }
Function with two data inputs with signature as char as 1st and int as 2nd parameter.

void action(int n,char c) {
cout<<“Output from int n, char c”<<endl;
for(int i=0;i<n;i++) cout<<c;
cout<<endl; }
Function with two data inputs with signature as int as 1st and char as 2nd parameter. So the signature is different and there is not ambiguity in calling a function.

int main() {
This will call the function with char 1st and int as 2nd parameter

This will call the function with int 1st and char as 2nd parameter

return 0;


  • The signature of a function means specification of parameters related to its type, count and exact order from left to right.
  • Function with similar data types but different order of parameters may be avoided if it can lead to confusion while implementation.

Suggested Filename(s): func-ol4.cpp


sunmitra| Created: 26-Aug-2018 | Updated: 28-Aug-2018|

Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning 2D Array Memory Addressing Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Multi-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues