C++ Questions

Q:

Which operator is used in catch-all handler?

A) ellipses operator B) ternary operator
C) string operator D) unary operator
 
Answer & Explanation Answer: A) ellipses operator

Explanation:

The ellipses operator can be represented as (…).

Report Error

View Answer Report Error Discuss

Filed Under: C++

0 5230
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 5077
Q:

What do you mean by reference variable in c++?

Answer

A reference variable provides an alias to a previously defined variable.


Data type & reference-name = variable name

Report Error

View answer Workspace Report Error Discuss

Subject: C++
Job Role: Software Architect

0 4787
Q:

Difference between Stack and Queue

Answer

Stack is a collection of objects that works in LIFO (Last in First out) mechanism while Queue is FIFO (First in First out). This means that the object that is inserted first is removed last in a stack while an object that is inserted first is removed first in a queue.

Report Error

View answer Workspace Report Error Discuss

Subject: C++

0 4787
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 4781
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

9 4770
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 4759
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 4757