Write a Cpp program to display two numbers using friend function?


Warning: Trying to access array offset on false in /home3/indiakep/public_html/wp-content/plugins/dw-question-answer/inc/Template.php on line 8
All QuestionsCategory: Cpp LanguageWrite a Cpp program to display two numbers using friend function?
Chetan Shidling Staff asked 6 years ago

I need short information.

1 Answers
Chetan Shidling Staff answered 6 years ago

Code:

#include <iostream>
using namespace std;
class sample
{
int a;
float b;
friend void print(sample);
};
void print(sample s)
{
s.a = 10;
s.b = 20;
cout<<“a:”<<s.a<<endl;
cout<<“b:”<<s.b<<endl;
}
int main()
{
sample s;
print(s);
return 0;
}

Output:

a:10
b:20