C++ Language | 10 Minute‐Test 7


Instruction

  • Total number of questions : 10.
  • Time alloted : 10 minutes.
  • Each question carry 1 mark.
  • No Negative marks
  • DO NOT refresh the page.
  • All the best :-).

1.

Which of the following statements are true?
int f(float)

A.
f is a function taking an argument of type int and retruning a floating point number
B.
f is a function taking an argument of type float and returning a integer.
C.
f is a function of type float
D.
none of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

The argument that is passed to a function f is of float type and the function
finally retruns a value that id is of integer type.

2.

Which of the two operators ++ and — work for the bool datatype in C++ ?

A.
None
B.
++
C.
-
D.
Both

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

Due to history of using integer values as booleans, if an integer is used as a boolean,
then incrementing will mean that whatever its truth value before the operation,
it will have a truth-value of true after it. However, it’s not possible to predict the result of —
given knowledge only of the truth value of x, as it could result in false.

3.

Which of these expressions will return true if the input integer v is a power of two?

A.
(v | (v + 1)) == 0;
B.
(~v & (v – 1)) == 0;
C.
(v | (v – 1)) == 0;
D.
(v & (v – 1)) == 0;

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

Power of two integers have a single set bit followed by unset bits.

4.

Choose the right option
string* x, y;

A.
x is a pointer to a string, y is a string
B.
y is a pointer to a string, x is a string
C.
both x and y are pointer to string types
D.
none of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

* is to be grouped with the variables not the data types.

5.

Pick the right option
Statement 1:A definition is also a declaration.
Statement 2:An identifier can be declared just once.

A.
Statement 1 is true, Statement 2 is false.v
B.
Statement 2 is true, Statement 1 is falsev
C.
both are false
D.
both are true

Your Answer: Option (Not Answered)

Correct Answer: Option B

Explanation:

An identifier can be declared many times must be defined just once.

6.

Identify the type of the variables.
typedef char* CHAR;
CHAR p,q;

A.
char*
B.
char
C.
CHAR
D.
unknown

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

The statement makes CHAR a synonym for char*.

7.

What is the output of this program by manipulating the text file ?

#include <stdio.h>

int main ()

{

if ( remove( "myfile.txt" ) ! = 0 )

perror( "Error" ) ;

else

puts( "Success" ) ;

return 0 ;

}

 

A.
Error
B.
Sucess
C.
Run Time error
D.
Can't say

Your Answer: Option (Not Answered)

Correct Answer: Option D

Explanation:

If myfile.txt exists, then it will delete the file. Else it will print an error message.
Output:
$ g++ out.cpp
$ a.out
Success

8.

What is the output of this program ?

#include

    using namespace std ;

    void duplicate ( int & a, int & b, int & c )

    {

        a * = 2 ;

        b * = 2 ;

        c * = 2 ;

    }

    int main ()

    {

        int x = 1 , y = 3 , z = 7 ;

        duplicate ( x, y, z) ;

        cout << x << y << z;

        return 0;

    }

 

A.
1468
B.
2812
C.
2614
D.
4216

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

We are passing the values by reference and modified the data on the function block.
Output:
$ g++ call1.cpp
$ a.out
2614

9.

Which of the following correctly declares an array ?

A.
int array[10];
B.
int array;
C.
array{10};
D.
array array[10];

Your Answer: Option (Not Answered)

Correct Answer: Option A

Explanation:

Because array variable and values need to be declared after the datatype only.

10.

What is meant by multiple inheritance ?

A.
Deriving a base class from derived class
B.
Deriving a derived class from base class
C.
Deriving a derived class from more than one base class
D.
None of the mentioned

Your Answer: Option (Not Answered)

Correct Answer: Option C

Explanation:

Multiple inheritance enables a derived class to inherit
members from more than one parent.

Submit your test now to view the Results and Statistics with answer explanation.