3
Q:

What is the output of this program ?

       #include
        using namespace std;
        int n(char, int);
        int (*p) (char, int) = n;
        int main()
        {
            (*p)('d', 9);
            p(10, 9);
            return 0;
        }
        int n(char c, int i)
        {
            cout << c <<  i;
            return 0;
        }

A) d99 B) d9d9
C) d9 D) compile time error

Answer:   A) d99



Explanation:

In this program, we have declared the values as integer instead of character, So it is printing as d99 but it will not arise an error.

Subject: C++
Q:

Which of the following is not the member of class?

A) Virtual function B) Static function
C) Friend function D) Const function
 
Answer & Explanation Answer: C) Friend function

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: C++
Job Role: Analyst , Database Administration , IT Trainer

19 9751
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 5384
Q:

What do you mean by friend function in C++ ?

Answer

Friends can be either functions or other classes. The class grants friends unlimited access privileges.

* The declaration of the function should be preceded by the keyword 'friend'.
* The function definition will not use the keyword or the scope operator '::'.


Thus, a friend function is an ordinary function or a member of another class.

Report Error

View answer Workspace Report Error Discuss

15 4001
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 5134
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 4998
Q:

Which of the following type casts will convert an Integer variable named amount to a Double type ?

A) (int to double) amount B) int (amount) to double
C) int to double(amount) D) (double) amount
 
Answer & Explanation Answer: D) (double) amount

Explanation:
Report Error

View Answer Report Error Discuss

6 4857
Q:

What is conversion operator ?

Answer

Class can have a public method for specific data type conversions.
for example:
class B
{
double value;
public  B(int i )
operator double()
{
return value;
}
};
B BObject;
double i = BObject; // assigning object to variable i of type double.
now conversion operator gets called to assign the value.

Report Error

View answer Workspace Report Error Discuss

11 3902
Q:

When should we use container classes instead of arrays?

Answer

It is advisable to use container classes of the STL so that you don’t have to go through the pain of writing the entire code for handling collisions, making sure its working well, testing it repeatedly with an overhead of time consumption.


Suppose you have some data that has values associated with strings and its fields consist of grades> in this situation you can directly use hash table instead of having it created by yourself.

Report Error

View answer Workspace Report Error Discuss

Subject: C++

8 4046