Function Overloading in C++ in Hindi फंक्शन ओवरलोडिंग क्या है

0 Deepak
Short Note : Function Overloading in C++ in hindi ?

Table of contents (toc)

Introduction

C++ language के एक से अधिक function को किसी शर्त के अनुसार एक ही नाम निर्धारित करने की सुविधा होती है। Function के एक ही नाम निर्धारित करने से प्रत्येक function में parameter की संख्या अलग अलग रखी जाती है। C++ Language का यह गुण फंक्शन ओवरलोडिंग (Function Overloading in hindi) कहलाता है। जब एक ही नाम वाले अनेक function अलग अलग प्रकार के parameters पर अलग अलग क्रियाएँ करते हैं तो function overloading use होता है।

Definition

Function Overloading different arguments और data type के साथ कई function को call करने की एक logical पद्धति है।

Declaration

निम्नलिखित दो function C++ में different है-

Float area (float radius);

Float area (float len, float wid);

यहाँ दोनों function के समान नाम हैं लेकिन argument की संख्या अलग अलग है। Function call की क्रिया के समय, C++ भाषा का compiler arguments की संख्या जाँचता है।

Program

#include <iostream>
#include <conio.h>
using namespace std;

float area(float radius);               // Function to calculate area of circle
float area(float len, float wid);       // Function to calculate area of rectangle

void main() {
    char ch;
    float radius, len, wid;
    clrscr();

    cout << "\nEnter C for Circle and R for Rectangle: ";
    cin >> ch;

    if (ch == 'C' || ch == 'c') {
        cout << "Enter radius: ";
        cin >> radius;
        cout << "The area of the circle is: " << area(radius);
    }
    else if (ch == 'R' || ch == 'r') {
        cout << "Enter length: ";
        cin >> len;
        cout << "Enter width: ";
        cin >> wid;
        cout << "The area of the rectangle is: " << area(len, wid);
    }
}

// Function definition for circle area
float area(float radius) {
    const float pi = 3.14159;
    return (pi * radius * radius);
}

// Function definition for rectangle area
float area(float len, float wid) {
    return (len * wid);
}(code-box)

Advantage

1. Function को समझने, debug करने और आसानी से use करने में सहायता प्रदान करता है।
2. Code का आसान प्रबंधन।
3. समान operation के लिए different function नामों के उपयोग को रोकता है।

लेख पसंद आया है तो इसे जरूर शेयर करें।

Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Check Out
Ok, Go it!