⟩ Generic catch handler is represented by ______________. a. catch(..,) b. catch(---) c. catch(…) d. catch( void x)
c. catch(…)
c. catch(…)
Explain the characteristics of friend functions?
Explain friend function?
What are friend classes?
What is the output of this program? #include <iostream> using namespace std; class Box { double width; public friend void printWidth( Box box ); void setWidth( double wid ); }; void BoxsetWidth( double wid ) { width = wid; } void printWidth( Box box ) { box.width = box.width * 2; cout << "Width of box " << box.width << endl; } int main( ) { Box box; box.setWidth(10.0); printWidth( box ); return 0; } a) 40 b) 5 c) 10 d) 20
Which keyword is used to declare the friend function? a) firend b) friend c) classfriend d) myfriend
Which rule will not affect the friend function? a) private and protected members of a class cannot be accessed from outside b) private and protected member can be accessed anywhere c) both a & b d) None of the mentioned
What is the output of this program? #include <iostream> using namespace std; class sample { int width, height; public void set_values (int, int); int area () {return (width * height);} friend sample duplicate (sample); }; void sampleset_values (int a, int b) { width = a; height = b; } sample duplicate (sample rectparam) { sample rectres; rectres.width = rectparam.width * 2; rectres.height = rectparam.height * 2; return (rectres); } int main () { sample rect, rectb; rect.set_values (2, 3); rectb = duplicate (rect); cout << rectb.area(); return 0; } a) 20 b) 16 c) 24
List the advantages of using friend classes?
What is the output of this program? #include <iostream> using namespace std; class base { int val1, val2; public int get() { val1 = 100; val2 = 300; } friend float mean(base ob); }; float mean(base ob) { return float(ob.val1 + ob.val2) / 2; } int main() { base obj; obj.get(); cout << mean(obj); return 0; } a) 200 b) 150 c) 100 d) 300
Where does keyword 'friend' should be placed? a) function declaration b) function definition c) main function d) None of the mentioned