Alien head

C++

Description: Practice questions for IT companies
Number of Questions: 25
Created by:
Tags: STL Templates Array Classes IT Companies Computer Basics
Attempted 0/25 Correct 0 Score 0

Which of the following data structures is not implemented by STL (Standard Template Library)?

  1. List

  2. Queue

  3. Stack

  4. Pointer


Correct Option: D
Explanation:

Pointer is not a data structure. It is a variable that contains the address of another variable and is not implemented in STL.

What is the notation of scope resolution operator?

  1. :

  2. *

  3. ::

  4. None of the above


Correct Option: C
Explanation:

Scope resolution operator is represented by :: . Hence, this is the correct answer.

Which of the following is involved in implementation of the concept of generic programming?

  1. Virtual functions

  2. Strings

  3. Templates

  4. Operator overloading


Correct Option: C
Explanation:

Templates are used to implement generic programming. They are of two types: function templates and class templates. Function templates are methods that can operate on any data type and class template can be used to write single code for multiple data types.

The member function can be defined outside class using

  1. size of operator

  2. scope resolution operator

  3. subscript operator

  4. none of the above


Correct Option: B
Explanation:

Scope is an enclosing context where values and expressions are associated. The scope resolution operator helps to identify and specifies the context to which an identifier refers. Hence, this is the correct answer.

Which of the following is not an unary operator?

  1. *

  2. ++

  3. --

  4. +


Correct Option: D
Explanation:

The operator + is a binary operator used for addition of two elements. Hence, this is the correct answer.

POD is used to describe

  1. C++ classes

  2. C classes

  3. C++ structures

  4. C structures


Correct Option: D
Explanation:

POD means plain old data and is used to describe C style structure which contains only data members.This term as used  in C++ structures,can contain data members as well as member functions. Hence, this is the incorrect answer.

What is the name of the term given to derived data type in which all data elements share the same location in memory?

  1. Pointers

  2. Structures

  3. Classes

  4. Unions


Correct Option: D
Explanation:

This is correct as all members share same memory location and the size of union is the size of the largest data element.

What is the name of the non-member function that can access all the private and protected members of a class?

  1. Virtual functions

  2. Static functions

  3. Friend functions

  4. Constructors


Correct Option: C
Explanation:

Friend functions are non-member functions which can access all the private and protected members of the class. An example of a friend function is class abc{ private: int f,s; public: friend int sum(abc x);}; Here, sum function can access even private members of class and is defined below -:int sum(abc x){return x.f+x.s;}.

In C++, what are the names given to the functions which are not actually called rather their codes are substitued every time they are invoked?

  1. Inline functions

  2. Constructors

  3. Destructors

  4. None of the above


Correct Option: A
Explanation:

Inline functions are very useful when we need to create efficient code as their code is expanded each time they are invoked. Inline functions are preceded by inline keyword. For example: inline int findlarge(int x, int y) {return x > y ? x : y;}. Hence, this is the correct answer.

When we are making all data members of class private, which property of OOP are we using?

  1. Inheritance

  2. Polymorphism

  3. Encapsulation

  4. None of the above


Correct Option: C
Explanation:

Encapsulation is a mechanism that binds together code and data which it manipulates and keeps both of them safe from outside interference and misuse. Hence, this is the correct answer.

What is the size of a far pointer?

  1. 1 byte

  2. 2 bytes

  3. 3 bytes

  4. 4 bytes


Correct Option: D
Explanation:

A far pointer is a pointer that can access all the segments of RAM and its size is 4 bytes.

What is the output of the following code snippet?

#include <iostream> using namespace std; int main () { int numbers[5]; int * p; p = numbers; *p = 10; p++; *p = 20;
p = &numbers[2]; *p = 30;
p = numbers + 3; *p = 40;
p = numbers; *(p+4) = 50;
for (int n=0; n<5; n++) cout << numbers[n] << , ; return 0; }

  1. 10, 20, 30

  2. 10, 20, 30, 40

  3. 10, 20, 30, 40, 50

  4. None of the above


Correct Option: C
Explanation:

A very simple concept has been used in this program, i.e. name of array basically contains base address and here we are initializing pointer to base address and then setting and incrementing pointer. Therefore, the correct answer is 10, 20, 30, 40, 50. 

Which of the following statements about abstract class is false?

  1. It must contain atleast one pure virtual function.

  2. Pointers to abstract class can be created.

  3. References to abstract classes can be created.

  4. Objects of abstract classes can be created.


Correct Option: D
Explanation:

It is not possible to create objects of abstract class as it contains pure virtual function which is not defined. This statement is false. Hence, it is the correct answer.

Which of the following is not a built-in stream in C++?

  1. cin

  2. cout

  3. cerr

  4. none of the above


Correct Option: D
Explanation:

Clog is a built-in stream that refers to the buffered version of cerr. The  above given four options are built in streams. Hence, this is the correct option.

Which of the following is not a type of iterator?

  1. Random access

  2. Bi-directional

  3. Linear

  4. Output


Correct Option: C
Explanation:

There is no iterator by the name linear in C++.

Identify the problem with the following function declaration.

int sum(int a = 0,int b);

  1. Function declaration is correct.

  2. Parameter cannot be given default value in function declaration.

  3. All parameters that take default value, must appear to right of those that do not.

  4. Default argument of parameter cannot be zero.


Correct Option: C
Explanation:

This option is correct as the only problem with the above function declaration is that a is intialized, but b is not. However, if a is intialized then b should also be initialized as explained in above option.

Which language has exercised the greatest influence in the development of C++?

  1. ALGOL

  2. PASCAL

  3. C

  4. Simula 67


Correct Option: D
Explanation:

Bjarne Strourstrup has acknowledged that Simula 67 was the greatest influence on him in the development of C++. Hence, this is the correct option.

What is the output of the following C code?

#include<stdio.h> int main() { short int i=0; for(i;++i;i>=99) printf(%d,i); return 0; }

  1. Infinite loop

  2. 1 to 32767 and then from -32768 to -1

  3. Compiler error

  4. Print from 1 to 99


Correct Option: B
Explanation:

Let Initial value be: i It does not affect any thing in the program. Checking condition: ++i It is incrementing the value of i by one in each iteration.  We know in c, zero means false. When value of i is zero, loop will terminate. Increment value: i >= 99 It is not incrementing the value of variable i.

It is clear, loop will terminate when value of variable i is zero. Hence, printf function will print: 1 to 32767 and then, from -32768 to -1   (range of short int) Hence, this option is correct.

What is the output of the following C++ code?

#include <iostream> using namespace std; int main() { cout.setf(ios::hex,ios::basefield); cout<<100; return 0; }

  1. 100

  2. 144

  3. 64

  4. 40


Correct Option: C
Explanation:

Here we have set basefield flag as hex which will display100 in hex and output is 64. Hence, the given option is correct.

Which of the following cast operators is used to override volatile attribute of variable?

  1. dynamic_cast

  2. static_cast

  3. const_cast

  4. reinterpret_cast


Correct Option: C
Explanation:

The const_cast is used explicitly override const and/or volatile attribute of variable. Hence, this is the correct answer.

Which of the following keywords is not defined in C++?

  1. Ttry

  2. catch

  3. throw

  4. finally


Correct Option: D
Explanation:

In C++, there is no finally keyword, which is defined in Java. Hence, this is the correct answer.

What is the output of the following C code?

#include<stdio.h> int main() { int i=0; for(;i++;printf(%d,i)); printf(%d,i); return 0; }

  1. Infinite loop

  2. Compilation error

  3. Runtime error

  4. 1


Correct Option: D
Explanation:

The basic thing that we need to remember in C is that zero means false. Now, the code inside for loop as condition is checked. Variable i is zero since we are using post-increment operator. Hence, loop is terminated and after that 1 is printed which is the final value of i. Therefore, this is the correct answer. 

What is the output of the following C++ code?

#include <stdio.h> int main() {
int a,b;
a = (b=2,b+3);
printf(%d,a);
return 0; }

  1. 2

  2. Garbage value

  3. 5

  4. None of the above


Correct Option: C
Explanation:

When expressions are seperated by comma operator, they are evaluated from left and the rightmost expressions only used for assignment. Hence, 5 is assigned to a and 5 is printed on the screen. This is the correct answer.

Which of the following is not a reserved word in Standard C++?

  1. Inline

  2. Continue

  3. Return

  4. Overload


Correct Option: D
Explanation:

Overload keyword is now obsolete and is no longer used or supported. It is not a part of Standard C++. It was preceded with function name in its definition to indicate that it was an overloaded function. Hence, this is the correct answer.

What is the output of the following C++ code?

#include <iostream> using namespace std; int main () { int a; for (a = 1; a <= 1; a++) cout << a++; cout<< <<a; return 0; }

  1. 1 1

  2. 1 2

  3. 1 3

  4. 1 4


Correct Option: C
Explanation:

As shown in the code, i is incremented two times. In first cout, 1 will be displayed and in second cout -since a is incremented twice by then, 3 is displayed. Hence, 1 3 is the correct output.

+ View questions