C++ Questions

Q:

In an AVL tree the balancing is to be done when the pivotal value is in range of

A) greater than 1 and less than -1 B) greater than -1 and less than 1
C) greater than 1 D) less than -1
 
Answer & Explanation Answer: A) greater than 1 and less than -1

Explanation:

Difference between the heights of left and Right subtrees in an AVL tree can never be greater than +1

Report Error

View Answer Report Error Discuss

Filed Under: C++

0 5667
Q:

What do vectors represent?

A) Static arrays B) Dynamic arrays
C) Stack D) Queue
 
Answer & Explanation Answer: B) Dynamic arrays

Explanation:

Vectors are sequence containers representing arrays that can change in size.

Report Error

View Answer Report Error Discuss

Filed Under: C++

0 5620
Q:

Which of the following is not a correct variable type?

A) real B) char
C) float D) double
 
Answer & Explanation Answer: A) real

Explanation:

A variable provides us with named storage that our programs can manipulate. Each variable in C++ has a specific type, which determines the size and layout of the variable's memory the range of values that can be stored within that memory and the set of operations that can be applied to the variable.

The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore. Upper and lowercase letters are distinct because C++ is case-sensitive −

 

Basic types of variables:


1. bool

Stores either value true or false.

2. char

Typically a single octet (one byte). This is an integer type.

3. int

The most natural size of an integer for the machine.

4. float

A single-precision floating point value.

5. double

A double-precision floating point value.

6. void

Represents the absence of type.

7. wchar_t

A wide character type.

Report Error

View Answer Report Error Discuss

10 5513
Q:

which keyword is used to define the macros in c++?

A) macro B) define
C) #define D) none of these
 
Answer & Explanation Answer: C) #define

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: C++

1 5344
Q:

What is meant by pure virtual function?

A) Function which does not have definition of its own. B) Function which does have definition of its own.
C) Function which does not have any return type. D) None of the mentioned
 
Answer & Explanation Answer: A) Function which does not have definition of its own.

Explanation:

As the name itself implies, it have to depend on other class only.

Report Error

View Answer Report Error Discuss

Filed Under: C++

2 5326
Q:

Give an example for the use of volatile keyword in c++ ?

Answer

Most of the times compilers will do optimization to the code to speed up the program. For example in the below code,


int k = 15;
while( k == 15)


{
// Do something
}


compiler may think that value of 'k' is not getting changed in the program and replace it with 'while(true)', which will result in an infinite loop. In actual scenario, the value of 'k' may be getting updated from outside of the program.


Volatile keyword is used to tell compiler that the variable declared using 'volatile' may be used from outside the current scope, so that compiler won't apply any optimization. This matters only in case of multi-threaded applications.


In the above example if variable 'k' was declared using volatile, compiler will not optimize it. In shot, value of the volatile variables will be read from the memory location directly.

Report Error

View answer Workspace Report Error Discuss

5 5214
Q:

How variable declaration in c++ differs that in c?

Answer

C requires all the variables to be declared at the beginning of a scope but in c++ we can declare variables anywhere in the scope. This makes the programmer easier to understand because the variables are declared in the context of their use.

Report Error

View answer Workspace Report Error Discuss

Subject: C++

1 5178
Q:

Values that are used to end loops are referred to as _____ values.

A) stop B) sentinel
C) end D) finish
 
Answer & Explanation Answer: B) sentinel

Explanation:
Report Error

View Answer Report Error Discuss

4 5093