What is the output of this program include using namespace s

What is the output of this program? #include using namespace std; int main() {int a; int &ref; = a; a = 15; cout NestedLessLess a NestedLessLess \" \" NestedLessLess ref NestedLessLess endl NestedLessLess endl; ref = 30; cout NestedLessLess a NestedLessLess \" \" NestedLessLess ref NestedLessLess endl NestedLessLess endl; ref = 45; cout NestedLessLess \" \" NestedLessLess a NestedLessLess \" \" NestedLessLess ref NestedLessLess endl NestedLessLess endl; int b = 100; ref = b - 5; cout NestedLessLess a NestedLessLess \" \" NestedLessLess ref NestedLessLess endl NestedLessLess endl; ref++; cout NestedLessLess a NestedLessLess \" \" NestedLessLess ref NestedLessLess endl NestedLessLess endl; ref = ref + a + b; cout NestedLessLess endl; cout NestedLessLess \" a == \" NestedLessLess a NestedLessLess endl; cout NestedLessLess \" b == \" NestedLessLess b NestedLessLess endl; cout NestedLessLess \" ref == \" NestedLessLess ref NestedLessLess endl NestedLessLess endl; return 0;}

Solution

Output of above program is: 15 15                                                                                                                                                                    

                                                                                                                                                                         

30 30                                                                                                                                                                    

                                                                                                                                                                         

45 45                                                                                                                                                                   

                                                                                                                                                                         

95 95                                                                                                                                                                    

                                                                                                                                                                         

96 96                                                                                                                                                                    

                                                                                                                                                                         

                                                                                                                                                                         

a==292                                                                                                                                                                   

b==100                                                                                                                                                                   

ref==292

explaination:

int &ref=a;    ref is just another name for variable a;

1) a=15

     therefore first output is 15 15

2) ref=30

     as a becomes 30 and output is 30 30

3) ref =45

      output is 45 45

4)b=100; ref = b-5; therefore ref becomes 95 and a also becomes 95

   output is 95 95

5) ref++; ref was 95, after incremnet it becomes 96

    therefore output is 96 96

6) ref= ref+a+b;

     ref=96

     a= 96

     b=100

   ref=ref+a+b=96+96+100= 292

therefore output is

     a==292

     b==100

    ref==292

 What is the output of this program? #include using namespace std; int main() {int a; int &ref; = a; a = 15; cout NestedLessLess a NestedLessLess \
 What is the output of this program? #include using namespace std; int main() {int a; int &ref; = a; a = 15; cout NestedLessLess a NestedLessLess \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site