Skip to main content

Area of Circle using Friend Function - C++program

1 min read Updated June 30, 2026
Share:
On this page (8sections)

About this program

This is an example program in c function example programs. Read the concept first: C++ Function Basics, then study the code and output below.

Definition Friend Function

If a function is friend function of a class, that friend function is not the actual member of the class.But which function has rights to access to all private and protected members (variables and functions).

For Better Understanding,

Area Of Circle Definition

The area of a circle is π (Pi) times the Radius squared, which is written A=πr2.

The area of a circle is written
A=?r2

here,

r = Radius
? = ~3.14

Simple Program for Friend Function

// Area Of Circle using Friend Function - C++Program 
// GCC Compiler 

#include<iostream>

class AreaOfCircle {
    int radius;
public:
    void get() {
        std::cout << "Enter the radius of Circle : ";
        std::cin >> radius;
    }
    friend float calculate(AreaOfCircle ob);
};

float calculate(AreaOfCircle ob) {
    return 3.14 * ob.radius * ob.radius;
}

int main() {
    AreaOfCircle object;
    object.get();
    std::cout<<"\nArea of Circle : "<<calculate(object);
}

Sample Output

Enter the radius of Circle : 5                                                                                                         
                                                                                                                                       
Area of Circle : 78.5  

Learn the concept first, then study the code:

Frequently Asked Questions

What does this C++ program do?
It is a C++ example program that demonstrates Area of Circle using Friend Function - C++program, including the complete source code and the expected sample output.
How do I compile and run this C++ program?
Save the code in a `.cpp` file, compile it with `g++ filename.cpp -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses reading user input and user-defined functions, illustrating a common pattern in C++ programming.

Related Tutorials

Search tutorials