C++ Questions

Q:

What is a Wrapper class?

Answer

Wrapper classes wrap primitive values in a class and offers utility to access them through objects. Some of the primitive wrapper data types are:


Byte, short, int, long, float, double, char, Boolean.


Example: 


Create a class name VectorAdd to populate it with integer values using the add(int, object) method.


public class VectorAdd


{


       public static void main(String argv[])


       {


             Vector v = new Vector();


             v.add(0,new Integer(10));


             v.add(1,new Integer(20));


             v.add(2,new Integer(30));


             for(int i=0; i < v.size();i ++)


             {


                  Integer iw =(Integer) v.get(i);


                  System.out.println(iw);


             }


       }


}

Report Error

View answer Workspace Report Error Discuss

Subject: C++

0 3523
Q:

What is a template?

A) A template is a formula for creating a generic class B) A template is used to manipulate the class
C) A template is used for creating the attributes D) none of the mentioned
 
Answer & Explanation Answer: A) A template is a formula for creating a generic class

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: C++

1 3463
Q:

Where does the exception are handled?

A) inside the program B) outside the regular code
C) both a & b D) none of these
 
Answer & Explanation Answer: B) outside the regular code

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: C++

1 3453
Q:

.What are Stacks? Give an example where they are useful.

Answer

A Stack is a linear structure in which insertions and deletions are always made at one end i.e the top - this is termed as last in, first out (LIFO). Stacks are useful when we need to check some syntex errors like missing parentheses. 

Report Error

View answer Workspace Report Error Discuss

Subject: C++

0 3447
Q:

How many items are presented in the associate container?

A) 2 B) 3
C) 4 D) 5
 
Answer & Explanation Answer: D) 5

Explanation:

There are 5 items presented in the associate container. They are set, multiset, map, multimap and bitset.

Report Error

View Answer Report Error Discuss

Filed Under: C++

1 3422
Q:

What are virtual functions?

Answer

Polymorphism is also achieved in C++ using virtual functions. If a function with same name exists in base as well as parent class, then the pointer to the base class would call the functions associated only with the base class. However, if the function is made virtual and the base pointer is initialized with the address of the derived class, then the function in the child class would be called.

Report Error

View answer Workspace Report Error Discuss

Subject: C++

1 3381
Q:

Differentiate between realloc() and free().

Answer

- Free() - A block of memory previously allocated by the malloc subroutine is freed by free subroutine. Undefined results come out if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null value, no action will take place.


- Realloc() - This subroutine changes the size of the block of memory pointed to by the Pointer parameter to the number of bytes specified by the Size parameter and returns a new pointer to the block. The pointer specified by the Pointer parameter must be created with the malloc, calloc, or realloc subroutines and should not be deallocated with the free or realloc subroutines. Undefined results show up if the Pointer parameter is not a valid pointer.

Report Error

View answer Workspace Report Error Discuss

Subject: C++

0 3366
Q:

What is the Run-Time Type Information?

A) Information about an object’s datatype at runtime B) Information about the variables
C) Information about the given block D) None of these
 
Answer & Explanation Answer: A) Information about an object’s datatype at runtime

Explanation:

With the help of RTTI, We can get the information about the data type at the runtime.

Report Error

View Answer Report Error Discuss

Filed Under: C++

1 3281