Saved Bookmarks
| 1. |
Identify the error(s) in the following code fragment:int x = 5;int y = 3;class Outer {public:int x;int a;static int s;class Inner {public:void f(int i){x = i;s = i;y = i;a = i;}};// Inner defination overInner I1; //Inner objectvoid g(it i){x = i;y = i;a = i;s = i;} }; //outer definition overOuter Ob1; // outer object int main(){Ob1.I1.f(3);//statement1Ob1.g(8); //statement2return 0;}What will be the values of ::x, ::y, Outer::x, Outer::a, Outer::s, Inner::a after statement 1 and statement 2 of above code? |
|
Answer» #include <iostream.h> #include<conio.h> int x=5; int y=3; class Outer { public: int x; int a; static int s; class Inner { public: int a; int x; void f(int i) { x = i; s = i; y = i; a = i; } }; Inner I1; void g(int i) { x = i; y = i; a = i; s = i; } }; int Outer::s; Outer Ob1; int main() { Ob1.I1.f(3); //statement1 Ob1.g(8); //statement2 return 0; } After statement 1 and statement 2 the values are as following: ::x = 5, ::y = 8, Outer::x = 8, Outer::a = 8, Outer::s =8 , Inner::a = 3 |
|