208k views
4 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 ();
}​

1 Answer

3 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 Daniil Ryzhkov
by
4.8k points