STL stands for Standard Template Library It is a library of container templates approved by the ANSI committee for inclusion in the standard C++ specification
Technology problems
Search Results
1. .What are Stacks? Give an example where they are useful.
Correct Answer: A Stack is a linear structure in which insertions and deletions are always made at one end ie 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
2. What are the advantages of using friend classes?
Correct Answer: - Friend classes are useful when a class wants to hide features from users which are needed only by another, tightly coupled class - Implementation details can be kept safe by providing friend status to a tightly cohesive class
Correct Answer: According to one-definition rule, C++ constructs must be identically defined in every compilation unit they are used in As per ODR, two definitions contained in different source files are called to be identically defined if they token-for-token identical The tokens should have same meaning in both source files Identically defined doesn?t mean character-by-character equivalence Two definitions can have different whitespace or comments and yet be identical
4. What is mandatory for designing a new container?
Correct 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(); vadd(0,new Integer(10)); vadd(1,new Integer(20)); vadd(2,new Integer(30)); for(int i=0; i < vsize();i ++) { Integer iw =(Integer) vget(i); Systemoutprintln(iw); } } }
Correct Answer: Stack unwinding is a process of calling all destructors for all automatic objects constructed at run time when an exception is thrown Destructors are called between the places where the exception was thrown and where it is caught
Correct 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
Correct Answer: Scope resolution operator allows a program to reference an identifier in the global scope that is hidden by another identifier with the same name in the local scope
Correct 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