adplus-dvertising
frame-decoration

Question

What is the following code segment doing?
void fn( ){
char c;
cin.get(c);
if (c != ‘\n’) {
fn( );
cout.put(c);
}
}

a.

The string entered is printed as it is.

b.

The string entered is printed in reverse order.

c.

It will go in an infinite loop.

d.

It will print an empty line.

Answer: (b).The string entered is printed in reverse order.

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the following code segment doing? void fn( ){ char c; cin.get(c); if (c != ‘\n’) { fn( ); cout.put(c); } }
akshay : June 26, 2023

how this code wrking