Multiple Choice

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1.

For inserting a new line in C++ program, which one of the following statements
can be used?

a) \n
b) \r
c) \t

2.Which of the following is used for comments in C++?

a) / comment;
b) // comment */
c) // comment

3. What will be the output of the following C++ program?

#include<iostream>
using namespace std;

int main()
{
int x = 5;
if (x <1)

cout<<"Hello";
}

a) Nothing
b) Run time error
c) Hello

5. Which of the following expression can be used as condition with if statement?

a) Arithmetic
b) Relational
c) Logical
d) Both B and C

6.Which of the following correctly declares an array in C++?


a) array{10};
b) array array[10];
c) int array;
d) int array [10];

7. If we stored five elements or data items in an array, what will be the index
address or the index number of the array's last data item?

a) 3
b) 5
c) 4

8.Which of the following best describes the purpose of cin in C++?

a) Outputting data to the console.


b) Accepting user input from the console.
c) Performing mathematical calculations.
d) Writing data to a file.

9. What is the correct way to use cin for inputting an integer variable num in C++?

a) cin>>num;
b) num<<cin;
c) cin<<num;
d) num>>cin
10. What is the primary purpose of the cin object in C++?

a) Accepting user input from the console.


b) Displaying output to the console.
c) Reading data from a file.
d) Performing mathematical calculations.

11. A for loop is also known as a _____ loop.

a) decrementing
b) incrementing
c) counting
d) recursive

12. Which of the following is the proper syntax of a for loop in C++?

a) for (int i = 0; i < 12) { }


b) for (int j = 0; j < 12; j++) { }
c) for(int q; q<j; ++) { }
d) for(int; int j++; j < 3) { }

13. Which of the following is the default return value of functions in C++?
a) int
b) char
c) float
d) void

14. What is the output of the given program?

#include<iostream>
using namespace std;
int fun(int x = 0, int y = 0, int z){

return (x + y + z);
}

int main()
{
cout << fun(10);
return 0;
}

a) 10
b) 0
c) Error
d) Segmentation fault

15. What is the purpose of a function prototype in C++?

a) To define a function
b) To declare a function before its usage
c) To initialize function variables
d) To terminate a function

You might also like