Posted in

Write C++ Program to display the cube of the number upto a given integer using friend function.

Write C++ Program to display the cube of the number upto a given integer using friend function.

C++ Program to display the cube of the number upto a given integer

If we declare a function friend int show(T4Tutorials); as a friend in a class T4Tutorials then this function int show(T4Tutorials object)  can access the private and protected members of the class T4Tutorials. You must know that a global function can also be declared as a  friend function of the class.

Syntax of friend function in C++

class class_name
{

friend return_type function_name(arguments);

}

Output

Please enter the number:

4

cube of 1 is: 1

cube of 2 is: 8

cube of 3 is: 27

cube of 4 is: 64

 

 CEO @ T4Tutorials.com
I welcome to all of you if you want to discuss about any topic. Researchers, teachers and students are allowed to use the content for non commercial offline purpose. Further, You must use the reference of the website, if you want to use the partial content for research purpose.

Leave a Reply

Contents Copyrights Reserved By T4Tutorials