153,212 views
25 votes
25 votes
What is output?

a include <iostreom.h>
void sub (float & x)
{ x + =2;
cout <<" \\x="<<x;
}
اے
void main ()
{ clrser ()
float x = 5.8
cout<<" \\x="<<x'
sob (x);
Cout <<"\\x="<<x
getch ();
}​

User Sciyoshi
by
2.8k points

1 Answer

30 votes
30 votes

Answer:

x=5.8

x=7.8

x=7.8

Step-by-step explanation:

I repaired the code somewhat (see below).

Since x is passed as a reference variable to the sub function, inside sub() the original variable is modified, so the changed value affects the variable declared in main().

If you would remove the & in sub, this wouldn't happen, and the variable in main would keep its value 5.8.

What is output? a include <iostreom.h> void sub (float & x) { x + =2; cout-example-1
User Jason Fox
by
3.1k points