C++ output type question

Q.  Predict the output:

int x = 786;
cout << setfill(‘*’) << setw(6) << x;

- Published on 17 Jul 15

a. 786***
b. **786
c. ***786
d. ******

ANSWER: ***786
 

    Discussion

  • Brijesh   -Posted on 23 Oct 15
    To access manipulators such as setw( ), setfill(), you must include in your program.
    According to given question
    int x = 786;
    cout << setfill(‘*’) << setw(6) << x;
    setw(6) function reserve 6 spaces in which 3 space will be occupied by * and the remaining three will be by 786. So the output will be ***786

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)