C++ MCQ -2

Question 1:

The void specifier is used if a function does not have return type.

a.       True

b.      False

 
Question 2:

You must specify void in parameters if a function does not have any arguments.

a.       True

b.      False

 
Question 3:

Type specifier is optional when declaring a function

a.       True

b.      False

 
Question 4:

Study the following piece of code and choose the best answer

int x=5, y=3, z;

a=addition(x,y)

a.       The function addition is called by passing the values

b.      The function addition is called by passing reference

 
Question 5:

In case of arguments passed by values when calling a function such as z=addidion(x,y),

a.       Any modifications to the variables x & y from inside the function will not have any effect outside the function.

b.      The variables x and y will be updated when any modification is done in the function

c.       The variables x and y are passed to the function addition

d.      None of above are valid.

 
Question 6:

If the type specifier of parameters of a function is followed by an ampersand (&Wink, that function call is

a.       pass by value

b.      pass by reference

 
Question 7:

In case of pass by reference

a.       The values of those variables are passed to the function so that it can manipulate them

b.      The location of variable in memory is passed to the function so that it can use the same memory area for its processing

c.       The function declaration should contain ampersand (&Wink in its type declaration

d.      All of above

 
Question 8:

Overloaded functions are

a.       Very long functions that can hardly run

b.      One function containing another one or more functions inside it.

c.       Two or more functions with the same name but different number of parameters or type.

d.      None of above

 
Question 9:

Functions can be declared with default values in parameters. We use default keyword to specify the value of such parameters.

a.       True

b.      False

 
Question 10:

Examine the following program and determine the output

#include <iostream>

using namespace std;

int operate (int a, int b)

{

                return (a * b);

}

float operate (float a, float b)

{

                return (a/b);

}

int main()

{

                int x=5, y=2;

                float n=5.0, m=2.0;

                cout << operate(x,y) <<“\t”;

cout << operate (n,m);

return 0;

}

 

a.       10.0      5.0

b.      5.0         2.5

c.       10.0      5

d.      10         2.5

Answers

 

1.       a. True

2.       b. False  [ parameters can be empty without void too!]

3.       b. False

4.       a. The function addition is called by passing the values

5.       a. Any modifications to the variables x & y from inside the function will not have any effect outside the function

6.       b. pass by reference

7.       b. The location of variable in memory is passed to the function so that it can use the same memory area for its processing

8.       d. None of above

9.       b. False

10.    d. 10       2.5

Similar Posts

  • C++ MCQ -5

    Question 1 Streams are a.       Abstraction to perform input and output operations in sequential media b.      Abstraction to perform input and output operations in direct access media c.       Objects  where a program can either insert or extract characters to and from it d.      Both a and c   Question 2 Which of the following is…

  • C++ MCQ -1

    Question 1. What is the correct value to return to the operating system upon the successful completion of a program? A. -1 B. 1 C. 0 D. Programs do not return a value.   Question 2. What is the only function all C++ programs must contain? A. start() B. system() C. main() D. program()  …

  • C++ MCQ -7

    Question 1 A variable is/are a.    String that varies during program execution b.    A portion of memory to store a determined value c.    Those numbers that are frequently required in programs d.    None of these   Question 2 Which of the following can not be used as identifiers? a.    Letters b.    Digits c.    Underscores d.   …

  • C++ MCQ -8

    Question 1 Identify the correct statement a. Programmer can use comments to include short explanations within the source code itself. b. All lines beginning with two slash signs are considered comments. c. Comments very important effect on the behaviour of the program d. both   Question 2 The directives for the preprocessors begin with a.   …

  • C++ MCQ -3

    Question 1: Find out the error in following block of code. If (x = 100)     Cout << ΓÇ£x is 100ΓÇ¥; a.       100 should be enclosed in quotations b.      There is no semicolon at the end of first line c.       Equals to operator mistake d.      Variable x should not be inside quotation   Question 2:…

  • C++ MCQ -6

    Question 1 In an assignment statement a=b; Which of the following statement is true? a.    The variable a and the variable b are equal. b.    The value of b is assigned to variable a but the later changes on variable b will not effect the value of variable a c.    The value of b is…

Leave a Reply

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