250+ TOP MCQs on Formatting and Answers

This section on C++ questions and puzzles on “Formatting”. One shall practice these questions and puzzles to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These programming puzzles can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ questions and puzzles on “Formatting” along with answers, explanations and/or solutions:

1. Which is used for formatting purpose in c++?
a) Whitespace
b) Container
c) &
d) Vector
Answer: a
Clarification: Whitespace is a term that refers to characters like spaces, tabs, and newlines that are used for formatting purposes.

2. How many number of spaces should be set in default tab?
a) 1
b) 2
c) 3
d) 4
Answer: d
Clarification: The default number of spaces is 4 in programming.

3. What can be improved by formatting the source code?
a) Memory
b) Address
c) User interface
d) Iterator
Answer: c
Clarification: By formatting your code, the user can easily understand it and can upgrade it without any complexity.

4. Choose the correct formatted code.
a)

   cout 

b)

   cout 


	

c) cout<<"Hai";
d) cout>>"Hai";
Answer: b
Clarification: If a long line that is broken into pieces is broken with an operator, the operator should be placed at the end of the line, not the start of the next line.

5. Choose the correct formatted code.
a) int a = 5;
b) int a=5;
c) int a =5;
d) int a5;
Answer: a
Clarification: Variable initialization should be done with one space on left and right of equal operator.

6. Choose the correct formatted code.
a)

   int main(){
   cout 

b)

   int main()
   {
   cout 

c)

   int main()
   {
   cout 


	

d)

   main()
   {
   cin>>5;

View Answer

Answer: b
Clarification: The braces that tell where a function begins and ends should be aligned with the function name and be on their own lines.

 
 

7. Which function allows you to set minimum width for the next input?
a) setfill
b) setw
c) setwidth
d) setheight
Answer: b
Clarification: setw function of iomanip header file allows you to set minimum width for the next input.

8. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     void showDate(int m, int d, int y)
  5.     {
  6.         cout << setfill('0');
  7.         cout << setw(2) << m << '/'
  8.         << setw(2) << d << '/'
  9.         << setw(4) << y << endl;
  10.     }
  11.     int main()
  12.     {
  13.         showDate(1, 1, 2013);
  14.         return 0;
  15.     }

a) 1,1,2013
b) 2013
c) 01/01/2013
d) 1120
Answer: c
Clarification: In this program, We are using the setw function to print the date in correct format.
Output:

$ g++ form.cpp
$ a.out
01/01/2013

9. What will be the output of the following C++ code?

  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         unsigned long x = 64;
  6.         cout << x << oct << x << endl;
  7.         return 0;
  8.     }

a) 64100
b) 48
c) 345
d) 496
Answer: a
Clarification: In this program, We are finding the octal number of given number by using oct function.
Output:

$ g++ form1.cpp
$ a.out
64100

10. What is the use of the function "showbase"?
a) Indicate the base used
b) Indicate the variable
c) Indicate the base used & variable
d) Indicate the derived
Answer: a
Clarification: showbase is used to indicate the base used.

Global Education & Learning Series - C++ Programming Language.

  250+ TOP MCQs on String Characters and Answers

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top