Example of friendly function in c++
Answers were Sorted based on User's Feedback
Answer / harry0009
#include<iostream.h>
class sample
{
int a,b;
public:
void setvalue()
{
a = 25;
b = 45;
}
friend float mean(sample s);
};
float mean(sample s)
{
return(float(s.a+& b)/20);
}
void main()
{
sample ;
x.setvalue
cout<<"mean value"<<mean(x);
getch();
}
| Is This Answer Correct ? | 11 Yes | 4 No |
How can I write functions that take a variable number of arguments?
What is the difference between struct and typedef struct in c?
which will return integer? a) int*s ( ) b) ( int* ) s( ) c) int ( *s ) ( )
What is the difference between abs() and fabs() functions?
Place the #include statement must be written in the program?
34.what are bitwise shift operators? 35.what are bit fields? What is the use of bit fields in a structure declaration? 36.what is the size of an integer variable? 37.what are the files which are automatically opened when a c file is executed? 38.what is the little endian and big endian? 39.what is the use of fflush() function? 40.what is the difference between exit() and _exit() functions? 41.where does malloc() function get the memory? 42.what is the difference between malloc() and calloc() function? 43.what is the difference between postfix and prefix unary increment operators?
What are the types of type qualifiers in c?
what is the output of the program and explain why?? #include<stdio.h> void main ( ) { int k=4,j=0: switch (k) { case 3; j=300; case 4: j=400: case 5: j=500; } printf (ā%d\nā,j); }
What are the parts of c program?
How is a two dimensional array passed to function when the order of matrix is not known at complie time?
What functions are used for dynamic memory allocation in c language?
What is c method?