C++ Interview Questions and Answers: A Comprehensive Guide
Ques: 1 can derived clss exception also be caught by the catch block?
Ans:
No
Ques: 2 What Is a B-Tree?
Ans:
The B-tree was invented in 1972 by R. Bayer and E. McCreight, and was designed from the start to create shallow trees for fast disk access. Shallow trees have few �levels�, We have to seek through them fewer times, and therefore they run quickly. Because seeks often require going to disk for the information we need, The performance increase with a shallow tree rather than a deeper tree can be substantial. B-trees are a powerful solution to the problem of disk-based storage; virtually every commercial database system has used variations on a B-tree for years. A B-tree consists of pages. Each page has a set of indices. Each index consists of a key value and a pointer. The pointer in an index can point either to another page or to the data you are storing in the tree. Thus, every page has indices that point to other pages or to data. If the index points to Another page, the page is called a node page; If the index points to data, the page is called a leaf page.
Ques: 3 What is Parsing Numeric Expressions?
Ans:
Numeric expressions are generally represented by the infix notation, In which the operator
Is placed between the operands and parentheses are used where necessary to indicate the order in which the operators are applied to the Expressions. Numeric expressions are best computed using a postfix notation also called reverse polish notation, In which the operator is placed after its two operands and parentheses are not required.
Ques: 4 What is the Parsing? And tell me how many types of Parsing?
Ans:
Parsing is a generic operation that identifies legal expressions and breaks them up into a
Form suitable for further processing. Parsing has applications in many different fields
Such as computer science, Interpreting human language, and so on. The main goal of parsing is to check the validity of an expression and make more sense out of it. The term �grammar� is commonly used in programming languages to identify legal expressions. There are two approaches commonly used during parsing of these two methods :
> Top-down approach: This method looks at the program first, and recursively identifies
Parts that are eventually matched to the input expression.
> Bottom-up approach: This method looks at the input expression and combines the pieces of the expression to make a legal program from it.
Ques: 5 What is Quadratic Probing?
Ans:
The Performance problem encountered by linear probing is caused by the cluster buildup That occurs as a result of the probing sequence. Quadratic probing uses a different sequence to avoid primary clustering.
Ques: 6 What is an Bucket Addressing?
Ans:
The Bucket Addressing Technique is similar to chaining in that collision resolution is performed
By using additional space. Whenever instead of using linked lists, We make use of buckets. A bucket can be defined as a block of space that can be used to store multiple elements that hash to the same position. In this method, We must give the buckets a fixed size; The Choice of this size can sometimes be tricky. Collisions are still possible because you may fill a bucket completely�in which case the key must be stored somewhere. This storage location can be an available bucket or an overflow area. A variation
Can be used to eliminate the need for buckets with fixed size: We can allow each bucket to contain a pointer to a dynamically allocated array.
Ques: 7 What is the chaining?
Ans:
The Chaining technique basically looks at the hash table as an array of pointers to linked
Lists. Each slot in the hash table is either empty or simply consists of a pointer to a linked
List. You resolve collisions by adding the elements that hash to the same slot to the linked
List to which that slot points. At the same time, deletions are easy, You simply delete elements
From the linked list.
Ques: 8 What is the Hash Function?
Ans:
The hash function is an important part of the hashing technique. This function is used to
Transform the keys into table addresses. The hash function we choose should be easy to
Compute and should be able to transform the keys into integers in the range 0 to TR-1. Because most of the commonly used hash functions are based on arithmetic operations, We should convert the keys to numbers on which arithmetic operations can be performed.
Ques: 9 What Is Recursion?
Ans:
Recursion is when a thing refers to itself or to an image just like itself. For a function, recursion means that the function calls itself. For an object,Recursion is when the object
Refers to things like itself by means of a pointer or a reference. Often, recursive structures and recursive functions go hand in hand. The best way to do many of the common operations on recursive structures is to use a recursive function.
Ques: 10 What is the Heap Operations?
Ans:
A Heap is a sequence in which the element with the largest value is always the first element
In the sequence. Elements are pushed into and popped out of the heap only at the front of the sequence. The STL priority queue is usually implemented as a heap. The Standard Library provides two heap-to-sequence conversion operations and two heap element access operations.
Ques: 11 Whats the requirement of Input Itrator?
Ans:
An input iterator is an iterator that must satisfy the following set of requirements which is there :
> Default Constructible: The iterator must have a default constructor so that it can
Be created without initializing it to any particular value. When an input iterator is
Created using its default destructor, It is an invalid iterator. It remains invalid until it
Is assigned a value.
> Assignable: The iterator must have a copy constructor and an overloaded assignment operator. These features allow for copying and assigning values to iterators.
> Equality Comparable: The iterator must have an overloaded equality operator == and an inequality operator !=. These operators allow for the comparison of two iterators.
Ques: 12 What are The Multimap Container?
Ans:
A Multimap is similar to a map except that elements can have duplicate keys.
Even the multimap class has a similar class definition to the map container class, W ith some exceptions. It has no subscripting operators because there may be more than one element that has the same key value. The insertion operation is always okay because duplicate keys are allowed.
Ques: 13 What is the The Deque Container?
Ans:
A Deque is bassically a type of vector .It is like a double-ended vector, It inherits the vector container class�s efficiency in sequential read and write operations. But in case of addition, the deque container class provides
Optimized front-end and back-end operations. These type of operations are same as implemented they are in the list container class, where memory allocations are engaged only for new elements. This feature of the deque class eliminates the need to reallocate the whole container to a new memory location, as the vector class has to do. Even deques are ideally suited for applications in which insertions and deletions
Take place at either one or both ends, and for which sequential access of elements is
Important.
Ques: 14 What is the mean of Memory Leaks?
Ans:
The Memory Leak is bassically a term of the memory . The Term memory leak is quite popular in the industry, But it isn�t often explained. Here�s
The idea: If you allocate memory using new and fail to reclaim that memory using delete, the memory is irretrievably lost until your program ends. It is as if the memory �leaked out� of your program.
Ques: 15 What is the mean of Utility Classes?
Ans:
A Utility class is bassicaly a class that contains grouped functionality. But no persistent data members or attributes. Although utility classes are not part of standard C++, some programmers like to create them. The UML offers support for them. The purpose of a utility class is to take a set of functionality and group them together in a common class. There is no need to create an instance of this class because each function in the class is declared static: We can simply use the functions contained in the class by fully qualifying the desired function name.
Ques: 16 What is the Realization?
Ans:
A Realization is a type of relationship , It is a relationship between two model elements, in which one model element or the client realizes the behavior that the other model element or the supplier specifies. A realization is displayed in the diagram editor as a dashed line with an unfilled arrowhead towards the supplier.
Ques: 17 What is the class diagram ?
Ans:
Class diagrams are bassically use for explain the classes in the terms of diagram.It serve two purposes:
> to represent the static state of classes and
> to exploit.
The relationships between those classes. In the early stages of the software development life cycle, it is important to note that the class diagram model attempts not only to define the public interface for each class but to define the associations, aggregations, and
Generalizations defined between the individual classes.
Ques: 18 Whats the use of Interaction Diagrams?
Ans:
Interaction diagrams are bassicaly used for the mdels behavior when models are work in the saeveral objects in a use case. They are reprasented how the objects collaborate for the behavior. Interaction diagrams do not give a in depth representation of the behavior. If we want to know what a specific object is doing for several use cases use a state diagram. Then we got particular behavior over many use cases or threads use an activity diagrams.
Ques: 19 What is the Interaction Diagrams?
Ans:
Interaction diagrams is bassicaly a type of model . Models behavior of use cases by describing the way groups of objects interact to complete the task. And The two kinds of interaction diagrams are sequence and collaboration diagrams.In this case that can dramatically improve the documentation and understanding of the intraction.
Ques: 20 What are the Limitations of CRC Cards?
Ans:
CRC Cards are very useful thing but its also have Many limitations which are there :
> its a inherent limitations
> Its also don�t capture the interrelationship among classes.
> the nature of the collaboration is not modeled well.
> CRC cards also don�t capture attributes.
> CRC cards do not capture this information.
Ques: 21 What is the CRC Cards?
Ans:
CRC basically a card but its uses in many fields which is mentioned are there, Its stands for Class, Responsibility, and Collaboration. A CRC card is nothing more than a 4×6 index card. This is a very simple, low-tech device allows you to work with other people in understanding the primary responsibilities of our initial set of classes. We assemble a stack of blank 4×6 index cards and meet around a conference table for a series of CRC card sessions. CEC cards are used to identify classes, responsibilities and collaborations between the objects in an object-oriented system.
Ques: 22 What is an Visualizations?
Ans:
The visualization is the bassically a way of presentation ,Its just a fancy name for the diagrams, pictures, screen shots, prototypes, and any other visual representations created to help through and design the graphical user interface
Of your product.
Ques: 23 What is the mean of Association?
Ans:
Assocaiation bassically called as third party whihc is creat a relatoionship of the commonly captured in the domain analysis is a simple association. An association suggests that two objects know of one another and that the objects interact in some way. An association is a mainly structural relationship that indicates that objects of one classifier, whihc classifier is a class and interface,That are connected and can navigate to objects of another classifier.
Ques: 24 What is the generalisation?
Ans:
Generalisation is the bassically type of Inheritance. But it is a diff from each other. Generalization is the mainly describes the relationship; Inheritance is the
Programming Lnaguage It is implementation of generalization�it is how we manifest generalization in code. Generalization implies that the derived object is a subtype of the base object. Its have a one type of account which is called as checking account .It is a bank account. Its relationship is symmetrical: Bank account generalizes the common behavior and attributes of checking and savings accounts.
Ques: 25 What is the mean of Modelling Language?
Ans:
Modelling Language is the bassically is type of artificial language .It is manily use for a expree the information or knowledge or system in a structure, that is defined by a consistent set of rules.The rules are used for interpretation of the meaning of components in the structure.
It is used for the the mainly some purposes :
> Graphical modeling languages use a bassically diagram techniques with named symbols that is represent concepts and lines that connect the symbols and that represent also relationships and various other graphical annotation to represent constraints.
> Textual modeling languages typically use standardised keywords accompanied by parameters to make computer-interpretable expressions.
Ques: 26 What is a constructor initializer list?
Ans:
Constructor Initializer List is a bassically a use for a some valid values.Its Main purpose of the contstuctor is to initialize the data members with some valid values.This can be done in two ways :
> To initialise a const
> To initialise a reference
Ques: 27 What is an iterator?
Ans:
An iterator is a bassically a type of object that represents a stream of data. It is Unlike a sequence, an iterator can only provide the next item. The for-in statement uses iterators to control the loop, and iterators can also be used in many other contexts.
Ques: 28 What is virtual inheritance?
Ans:
Inheritance is a bassically can be private , public, or virtual. With virtual inheritance there is only one copy of each object even if the object appears more than once in the hierarchy.
Ques: 29 define destructor as static?
Ques: 30 What is placement new?
Ans:
The placement-new operator constructs an object on a pre-allocated buffer. The pre-allocated buffer has to be allocated on the heap. Operator new allocates memory from the heap, on which an object is constructed. Standard C++ also supports placement new operator, which constructs an object on a pre-allocated buffer. This is useful when building a memory pool, a garbage collector or simply when performance and exception safety are paramount.
Ques: 31 What is multithreading
Ans:
Multithreading is defined as :It is the task of creating a new thread of execution within an existing process rather than starting a new process to begin a function. It is the ability of an operating system to concurrently run programs that have been divided into subcomponents, or threads.
Ques: 32 What is the difference between static link library and dynamic link library?
Ans:
Many diff are there :
Static Link Library : Static linking is the abssicaly a type of method, It is a original method used to combine an application program with the parts of various library routines. The linker is given your compiled code, containing many unresolved references to library routines.
Ques: 33 What are smart pointer?
Ans:
A smart pointer is a type of pointer but its an smart. It ia an abstract data type that simulates a pointer while providing additional features, such as automatic garbage collection. In the smart pointer have a very most imp features in the pointers and its have additional features are intended to reduce bugs caused by the misuse of pointers while retaining efficiency. Smart pointers typically keep track of the objects that point to them for the purpose of memory management.
Ques: 34 Why PCM is used?
Ans:
we know that PCM is digital, A more general reason would be that digital signals are easy to process by cheap standard techniques. PCM bassically use for other processes :
> Filtering
> Sampling
> Quantizing
> Encoding
Ques: 35 what is pulse code modulation?
Ans:
Pulse code modulation is decribed as a PCM .Now a Days we know its a digital world In this time it is the heart of technology in communications . It�s a process in which analog signals are converted to digital form. The analog signal is represented by a series of pulses and non-pulses. At this stage to fully understand we can refer back to the notes on signals.
Ques: 36 What is the difference between static link library and dynamic link library?
Ans:
Basic diff are there :
> Static libraries are linked at compile time.
> Dynamic libraries are linked at runtime.
Ques: 37 Tell us the Name the operators that cannot be overloaded??
Ans:
The Name of operatores are there which can nt be overladed ……. > sizeof, > [.] > * > – > :: > ?:
Ques: 38 What is the difference between class and structure?
Ans:
Many DIff are there :
> In C Structure is bassically used to bundle different type of data types together to perform a particular functionality. But In case of C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public.
And we are talking about the class, It is a successor of Structure. By default all the members inside the class are private.
Ques: 39 How do you access the static member of a class
Ans:
We can access the static member of the class in this syntax : ::
Ques: 40 What are the defining traits of an object-oriented language?
Ans:
The defining traits of an object-oriented langauge are there : > encapsulation > inheritance > polymorphism
Ques: 41 hat is a nested class?
Ans:
A Nested class is bassically a normal class which is enclosed within the scope of another class. It is mainly declared within the scope of another class. The name of a nested class is local to its enclosing class. Unless you use explicit pointers, references, or object names, declarations in a nested class can only use visible constructs, including type names, static members, and enumerators from the enclosing class and global variables.
Ques: 42 What is the Standard Template Library (STL)?
Ans:
STL is a bassically standard librry templates whihc is approved by ANSI C++ specification. Its Library contains have a many templates which is also appoved by them. A programmer launches into a discussion of the generic programming model, iterators, allocators, algorithms, and such, has a higher than average understanding of the new technology that STL brings to C++ programming.
Ques: 43 What are the advantages of inheritance?
Ans:
Adavantages of Inheritance are there:
> It permits code reusability.
> Its saves time in program development.
> It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system becomes functional.
Ques: 44 What is the difference between a baller and a reference?
Ques: 45 What is an explicit constructor?
Ans:
A Explicit construtor is bassically means a conversion constructor always declared with the explicit keyword. The compiler does not use an explicit constructor to implement an implied conversion of types. It�s purpose is reserved explicitly for construction.
Ques: 46 What’s an initializer list?
Ans:
A constructor initializer list is the bassically syntactical construct, It allows the user to specify to the compiler how to initialize member variables of a class upon construction of an instance of that class.
Ques: 47 What’s the difference between a struct and a class?
Ans:
Many diff are there in strut and a class .Class members is a private by default but in case of struts members are by default public. Ans the class is a C++ element and struct is a C one. We can have functions, virtual functions, inheritance, different access modifiers private, protected, public in a class but probably not in a struct. A struct generally holds member variables only.”
Ques: 48 When would you use private inheritance?
Ans:
Many uses of Private Inheritance :
> It can introduce unnecessary multiple inheritance .
> It allows members of Car to convert a Car* to an Engine*.
> It allows access to the protected members of the base class.
> It allows Car to override Engine’s virtual functions.
> This makes it slightly simpler to give Car a start() method that simply calls through to the Engine’s start() method.
Ques: 49 Why is iostream better than stdio?
Ans:
Isostream is better than stdio like that :
> The library offers two major advantages compared to C’s :
It can be extended to support user-defined types. And it’s type-safe. If programmer can give a complain about have give a poorer performance and a bloated ,And unintuitive interface.
Ques: 50 What are the problems with a tree-style hierarchy?
Ans:
Tree-style hierarchy is type of a method and system is provided for generating a tree-style graphical representation that depicts simultaneously hierarchical and non-hierarchical interrelationships among a set of entities. There is two sets of specifications are acquired. One set describes a set of hierarchical interrelationships. The other set describes a set of non-hierarchical interrelationships among the same set of entities. Based on the two sets of specifications,The generated tree-style graphical representation is displayed, as a graphical user interface, on a display device.
Ques: 51 What is a mutable member?
Ans:
Its is type of memeber which one that can be modified by the class even when the object of the class or the member function doing the modification is const.
Ques: 52 What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator.
Ans:
An internal iterator is working on stp by step, Its implemented with member functions of the class .An external iterator is implemented as a separate class that can be “attach” to the object that has items to step through.
An external iterator has the advantage :
> that many difference iterators can be active simultaneously on the same object.
Ques: 53 What�s the auto keyword good for?
Ans:
At the end of the object scope It declares an object with automatic storage duration. Which object will be destroyed. Many variables in functions that are not declared as static and not dynamically allocated have automatic storage duration by default. Local variables which is Local but they are not declare within a scope; They are often called automatic variables because they automatically come into being when the scope is entered and automatically go away when the scope closes. The keyword auto makes this explicit, It is never necessary to declare somethin becouse local variables are default.
Ques: 54 What is abstraction?
Ans:
Abstraction is the bassically type of process, It is the process of hiding the details and exposing only the essential features of a particular concept or object.
Ques: 55 What is friend function?
Ans:
Its not a actually members of the class it cn access only private and protected member of the class .The function acts as a friend to a class. As a friend of a class, it must be listed in the class definition.
Ques: 56 Why are arrays usually processed with for loop?
Ans:
It is bassically using for traversing the index of array thats The Real power of arrays , Accessing each element with the same expression a[i]. All the is needed to make this work is a iterated statement in which the variable a[i] serves as a counter, incrementing from 0 to a.Length -1.
Ques: 57 Can you think of a situation where your program would crash without reaching the breakpoint which you set at the beginning of main()?
Ans:
When main() isn’t invoked C++ allows for dynamic initialization of global variables. It is possible that global initialization will invoke some function. When main() is not entered this function crashes the crash will be occur. Non-static const data members and reference data members cannot be assigned values; instead, We should use initialization list to initialize them.
Ques: 58 How can you tell what shell you are running on UNIX system?
Ans:
when we can do the Echo RANDOM. Then we got return a undefined variable.
> If we are from the C-Shell, just we will got return value prompt,
> If we are from the Bourne shell, and in a 5 digit random numbers.
> If we are from the Korn shell. We could also do a ps -l and look for the shell with the highest PID.
Ques: 59 Define a constructor – What it is and how it might be called (2 methods)
Ans:
Constructor is atype of member function in the class, with the name of the function being the same as the class name. It also specifies how the object should be initialized.
There are two Ways of calling constructor: > Automatically by complier when an object is created. It is called a Implicitly method. > Calling the constructors explicitly is possible, but it makes the code unverifiable.
Ques: 60 What is a node class?
Ans:
A node class is a class that is defined as :
> Relies on the base class for services and implementation,
> It Provides a wider interface to the users than its base class,
> It Relies primarily on virtual functions in its public interface.
>It Depends on all its direct and indirect base class.
> It can be understood only in the context of the base class.
> It can be used as base for further derivation.
> It can be used to create objects.
> A node class is a class that has added new services or functionality beyond the services inherited from its base class.
Ques: 61 What is the difference between an ARRAY and a LIST?
Ans:
Many diff are there :
> Array is collection of homogeneous elements. But in the case of List, Its a collection of heterogeneous elements.
> For Array memory allocated is static and continuous. But for List memory allocated is dynamic and Random.
> Array is User need not have to keep in track of next memory allocation.But in List, User has to keep in Track of next location where memory is allocated.
Ques: 62 What are the conditions that have to be met for a condition to be an invariant of the class?
Ans:
Conditions ae there :
> The condition should hold at the end of every constructor.
> The condition should hold at the end of every mutator (non-const) operation.
Ques: 63 What is a scope resolution operator?
Ans:
A scope resolution operator is defened as (::), It can be used to define the member functions of a class outside the class.
Ques: 64 What do you mean by binding of data and functions?
Ans:
Binding of data and functions is bassicaly called as Encapsulation.
Ques: 65 What are 2 ways of exporting a function from a DLL?
Ans:
Two Ways are there :
> Taking a reference to the function from the DLL instance.
> Using the DLL �s Type Library
Ques: 66 How can a base pointer access the members of a derived class?
Ans:
Base pointer is only point to the object of derived class but it cannot access the members of the derived class .
Ques: 67 What is constructor or ctor?
Ans:
Constructor maily use to creates an object and initializes it. Its also use in creates a vtable for virtual functions. It is not a method, It is different from other methods in a class.
Ques: 68 What is difference between template and macro??
Ans:
The macro is expanded without any special type checking.Its expanded by the prepocessors. And It will show up in expanded form during debugging. If macro parameter has a postion incremented variable ( like c++ ), the increment is performed two times.Because compiler error messages will refer to the expanded macro, rather than the macro definition itself.
Ques: 69 What are the Extern Storage class?
Ans:
Extern Storage Class is bassically a static variable whose definition and placement is determined when all object and library modules are combined or linked to form the executable code file. It can be visible outside the file where it is defined.
Ques: 70 What are the Static Storage class?
Ans:
Static Storage Class is bassicaly a variable that is known only in the function that contains its definition but is never destroyed and retains its value between calls to that function. It exists from the time the program begins execution
Ques: 71 What are the Register Storage class?
Ans:
Register Storage Class in C++ bassically is a type of auto variable. A suggestion to the compiler to use a CPU register for performance.
Ques: 72 What is the Auto Storage Class?
Ans:
Auto Storage Class is bassically the default. Variables are automatically created and initialized, When they are defined and are destroyed at the end of the block containing their definition. They are not visible outside that block.
Ques: 73 What are C++ storage classes?
Ans:
C++ storage classes are there: > Auto > Register > Static > Extern
Ques: 74 What happens when we make call “delete this;” ??
Ans:
When we call “delete this” then two cases are generate in the code . First, if it executes in a member function for an extern, static, or automatic object, the program will probably crash as soon as the delete statement executes. There is no portable way for an object to tell that it was instantiated on the heap, so the class cannot assert that its object is properly instantiated.
Second, when an object commits suicide this way, the using program might not know about its demise. As far as acc to the instantiating programme, the object remains in scope and continues to exist even though the object did itself in. Subsequent dereferencing of the pointer can and usually does lead to disaster.
Ques: 75 What does extern “C” int func(int *, Foo) accomplish?
Ans:
One can link to code compiled by a C compiler becouse it will be turn off “name mangling” for function.
Ques: 76 What are the access privileges in C++? What is the default access level?
Ans:
The access privileges in C++ are :
> private
> public and
> protected.
The default access level assigned to members of a class is private. Private members of a class are accessible only within the class and by friends of the class.
Protected members are accessible by the class itself and it’s sub-classes.
Public members of a class can be accessed by anyone.
Ques: 77 What is the type of conversion operator?
Ans:
Conversion operator bassically two type are there:
> Impliit Conversion – Its operators do not require a type cast to be specified in source code to perform the conversion.
> Explicit Conversion – Its operators require a type cast be present in the source code to perform the conversion.
Ques: 78 What is conversion operator??
Ans:
Conversion operators bassically is a method. Its convert an object from one type to another type. Class can have a public method for specific data type conversions.
Ques: 79 What is conversion constructor?
Ans:
Conversion Constructor is bassically related to typecasting of user defined datatypes ie Convertion of one class object to other class object. Constructor with a single argument makes that constructor as conversion constructor and it can be used for type conversion.
Ques: 80 When are copy constructors called?
Ans:
There are many important places where a copy constructor is called.
> When an object is created from another object of the same type.
> When an object is passed by value as a parameter to a function.
> When an object is returned from a function.
> when a function returns an object of that class by value.
> when the object of that class is passed by value as an argument to a function.
> when we construct an object based on another object of the same class.
> When compiler generates a temporary object.
Ques: 81 What is copy constructor?
Ans:
Copy Constructor is defined as :
> A constructor function with the same name as the class
> Used to make deep copy of objects.
> Initializes object member variables with another object of the same class.
> A New object from an existing one by initialization.
Ques: 82 What is the difference b/w const char *myPointer and char *const myPointer?
Ans:
Diff are there :
> Const char *myPointer is a non constant pointer to constant data.But in the case of char *const myPointer is a constant pointer to non constant data.
Ques: 83 Give us List out some of the OODBMS available?
Ans:
Lit is there :
> GEMSTONE/OPAL of Gemstone systems,
> ONTOS of Ontos,
> Objectivity of Objectivity Inc,
> Versant of Versant object technology,
> Object store of Object Design,
> ARDENT of ARDENT software,
> POET of POET software.
Ques: 84 Give me a any two main roles of Operating System?
Ans:
main roles are there : > As a resource manager > As a virtual machine
Ques: 85 What is �*� operator called as?
Ans:
�*� operator is using for deference that’s why we can called as deferece operator or indirection operator.
Ques: 86 How are prefix and postfix versions of operator++() differentiated?
Ans:
In the Opertor ++() have a dummy paprameter of Post fix version but in case of prefix version its doesn’t have.
Ques: 87 What is containership?
Ans:
Containership is bassically type of hierarchy. It can also be called containment hierarchy. In C++ Possessing of objects of other classes in a class is called containership or nesting.
Ques: 88 What is overriding?
Ans:
Overriding is bassically a Providing a declaration which matches another declaration of the same name, thereby hiding the existing declaration. And its a ability to change the definition of an inherited method or attribute in the derived class.
Ques: 89 What are pointer variables?
Ans:
Pointer Variables is the bassically that Variables which is hold memory addresses.That variable called pointer variables.
Ques: 90 What are pointer constants?
Ans:
Pointer constants is bassically a term in the memory addresses in a computer which is cannot be changed.
Ques: 91 What is run time polymorphism?
Ans:
Run time polymorphism is bassically called as Binding of an object to the corresponding function at run time.Its a method overriding. It takes place at runtime and looks peticular to the object type.
Ques: 92 What are C-strings or C-style strings?
Ans:
C-style strings are bassially a type of arrays of chars with a little bit of special sauce to indicate where the string ends. And in these type of arrays are also string literals, such as “this”. In reality, both of these string types are merely just collections of characters sitting next to each other in memory. And its mainly use for The null terminated character arrays used to store and manipulate strings .
Ques: 93 What are abstract base classes?
Ans:
Abstract Base Classes are classes which cannot be used to create any objects.
Ques: 94 What are �do-nothing� functions?
Ans:
�Do-nothing� functions bassicaly type of ones a function which are just defined but are not used.
Ques: 95 What is callback function?
Ans:
Callback function is the type of pointer for a function.
Ques: 96 What is a stream? And define the types of Stream?
Ans:
Its a type of interface b/w the program and the input/output devices is called a stream.
Types of Streams :
Input Stream : The source stream which sends data to the program is called input stream.
Output Stream : The destination stream which receives output from the program is called output stream.
Ques: 97 What are stream classes?
Ans:
Strem classes are bassicaly a hierarchy of classes which are used to deal with console and disk files using different streams are called stream classes.
Ques: 98 What is the limitation of �cin�?
Ans:
it cannot read multiple words.
Ques: 99 What are the parts of a file name?
Ans:
A file name includes a primary name and an optional period with an extension.
Ques: 100 What are the ways of opening a file?
Ans:
many ways are there for open the file :
> A file can be opened using the constructor function of the class .
And
> using the member function open () of the class.
Ques: 101 What is the use of template classes and functions?
Ans:
Template classes and functions are usually use for eliminate redundancy or ambiguity of code and help in easier program or user friendly programe development.
Ques: 102 What is the use of using?
Ans:
Using is bassically a namespace scope. Its directive used to declare the accessibility of identifiers declared within a namespace scope.
Ques: 103 What is the use of exception handling?
Ans:
Exception handling is bassically used to detect exceptions becouse it can be taken a corresponding action.
Ques: 104 What is a file?
Ans:
A file is bassically a collection of related data. Which is store on a disk.
Ques: 105 What are manipulators?
Ans:
Manipulators bassically a type of functions. That are included in the I/O statements to alter the parameters of a stream are called manipulators.
Ques: 106 What is EOF?
Ans:
EOF bassically stands for End of File, It is used to check for the end of file when a file is being read.
Ques: 107 What are storage qualifiers in C++ ?
Ans:
In C++ storage qualifier bassically a type of :
Const
Volatile
Mutable
Const keyword indicates that memory once initialized, should not be altered by a program.
Volatile keyword indicates that the value in the memory location can be altered even though nothing in the program code modifies the contents.
Ques: 108 Give examples for synchronous exceptions?
Ans:
Syncronous Eceptions examples are there : > Out of range index > division by zero > overflow etc.
Ques: 109 In which class is the function eof () present?
Ans:
class ios.
Ques: 110 What is the difference between ios::ate and ios::app mode?
Ans:
diff are there : > Mode is that ios::ate mode allows us to add data or change data anywhere in the file But In ios::app mode allows us to add data only to the end of file.
Ques: 111 What does the file mode parameter ios::binary mean?
Ans:
It is the bassically means the file to be opened is a binary file.
Ques: 112 What are the types of file pointers?Nad whats the use?
Ans:
Two types of the File Pointers :
> Input pointer : The input pointer is used to read the contents in a particular file location.
And
> Output pointer : The output pointer is used to write the contents in a particular file location.
Ques: 113 What is the use of file pointers?
Ans:
File pointers are bassically use for moving the files and docs.Its used to move in the file while writing or reading.
Ques: 114 whats the use of seekp() and seekg()?
Ans:
they are using bassicaly move the I/O in speciafic positions :
> Seekp () is used to move output/put pointer to a specified position.
> seekg () is used to move input/get pointer to specified position.
Ques: 115 What is the use of tellg ()?
Ans:
tellg () provides a information about the current position of input/get pointer.
Ques: 116 What is the use of tellp ()?
Ans:
tellp ()use for the poitner postion : > Its provides the current position of output/put pointer.
Ques: 117 What are the functions used to handle single character at a time?
Ans:
they have a two functions whihc used to handle single charecter at a time : > put () And > get ()
Ques: 118 What is function overloading and operator overloading?
Ans:
Diff are there:
Function overloading:
C++ defines a same name of the fuctions are in diff set of paprameters.As long as the type is concerned. This capability is called function overloading. When an overloaded function is called, the C++ compiler selects the proper function by examining the number, types and order of the arguments in the call. Function overloading is commonly used to create several functions of the same name that perform similar tasks but on different data types.
Operator overloading :
Operator Overloading works on objects of user defned classes becouseits alows existing C++ operators to be redefined .Overloaded operators are syntactic sugar for equivalent function calls. They form a pleasant facade that doesn’t add anything fundamental to the language.
Ques: 119 Define the parameterized macros?
Ans:
Parameterized macros are use for the parameters . It is the one which consist of template with insertion points for the addition of parameters.
Ques: 120 Define the generic programming?
Ans:
Generic Programmng is type of method. The method in which generic types are used as arguments in algorithms for different data types and data structures is called generic programming.
Ques: 121 What is Memory alignment??
Ans:
The Word alignment basscially means the tendency of an address pointer value to be a multiple of some power of two. That’s why a pointer with two byte alignment has a zero in the least significant bit. And a pointer with four byte alignment has a zero in both the two least significant bits and all .
Ques: 122 What is overflow error?
Ans:
Overflow error bassically a type of arithmatic errors.It’s caused by the result of an arithmetic operation being greater than the actual space provided by the system.
Ques: 123 What is the use of export?
Ans:
Export is bassicaly used to instantiate the non inline template classes and its used also in functions from different files.
Ques: 124 Give an example for asynchronous exceptions?
Ans:
Asynchronous exceptions example is Keyboard interrupt.
Ques: 125 What are the basic segments of error handling code?
Ans:
Error handling is a bassicaly broad category that includes responding to many kinds of errors that are thrown during compilation or at run time. Errors that happen at compile time are often easier to identify.Its code consists of two segments one for detecting and throwing exception and the other for catching the exception.
Ques: 126 What is the use of application wizard?
Ans:
Application Wizard provides many things .Its use for ………
> quick access to your applications, documents and pictures.
> Open favorite applications and groups of applications.
> Quickly open recent applications.
> Force applications to open using Rosetta or in Classic.
> Open applications automatically at startup.
> Quit multiple or all applications at one time.
> Quit background-only applications and the Finder.
> Force applications to quit or relaunch them.
> Switch between applications.
> Bring specific windows to the front when making applications active.
> Show and hide groups of applications.
> Turn on single application mode.
> frame work for creating initial applications.
Ques: 127 Write the different forms of throw?
Ans:
the different forms of throw are there : Throw (exception); Throw exception; Throw;
Ques: 128 What is mean of translation?
Ans:
Translation is thebasically interpreting of the meaning of a text and the subsequent production of an equivalent text, That’s called a “translation,” that communicates the same message in another language. It is a creation of a new program in an alternate language which is logically equivalent the source language program.
Ques: 129 Give the name some pure object oriented languages
Ans:
Names are there: > Smalltalk > Java > Eiffel > Sather.
Ques: 130 What is the use of try block?
Ans:
Try block is the bassically used to generate exceptions.The try block is a series of statements beginning with the keyword Try, followed by an exception type and an action to be taken.
Ques: 131 How can you catch all the exceptions without specifying individually?
Ans:
All the exceptions can be caught without specifying them individually by using ellipsis with catch.
Syntax is there:
Catch (�)
{
���
���
}
Ques: 132 What is an orthogonal base class?
Ans:
Its a normally a base class if two base classes have a no overlapping properties methods they are said to be orthogonal to each other. A class can be derived from these two base classes with no difficulty.
Ques: 133 What is the use of Microsoft foundation class library?
Ans:
The Microsoft Foundation Class Library also called as A Microsoft Foundation Classes or MFC. It is bassically a library that wraps portions of the Windows API in C++ classes,and including functionality that enables them to use a default application framework. Classes are defined for many of the handle-managed Windows objects and also for predefined windows and common controls. MFC library would help us reduce the code and development time.
Ques: 134 What is the use of class wizard?
Ans:
class wizard bassically use for help in develope a MFC applications, Its help also in customizing the classes.
Ques: 135 What is inline function??
Ans:
The inline keyword bassically tells the compiler to substitute the code within the function definition for every instance of a function call. Whenever, substitution occurs only at the compiler’s discretion. For example, the compiler does not inline a function if its address is taken or if it is too large to inline.
Ques: 136 Whit is the mean of precondition and post-condition to a member function
Ans:
Precondition is defined as a condition that must be true on entry to a member function. If preconditions are never false it means class is used correctly . An operation is not responsible for doing anything sensible if its precondition fails to hold. For example, the interface invariants of stack class say nothing about pushing yet another element on a stack that is already full. We say that isful() is a precondition of the push operation. Post-condition is defines as a condition that must be true on exit from a member function if the precondition was valid on entry to that function. A class is implemented correctly when post-conditions are never false. For example, after pushing an element on the stack, we know that isempty() must necessarily hold. This is a post-condition of the push operation.
Ques: 137 What is multiple inheritance(virtual inheritance)? What are its advantages and disadvantages?
Ans:
Multiple Inheritance is bassically a process , The process when a child can be derived from more than one parent class. The advantage of multiple inheritance is that it allows a class to inherit the functionality of more than one base class thus Its allowing for modeling of complex relationships. And The disadvantage of multiple inheritance is that it can handle to a lot of confusions like ambiguities and all …. When two base classes implement a method with the same name.
Ques: 138 What is a nested class? Why can it be useful?
Ans:
Nested classes bassically useful for organizing code and controlling access and dependencies. Nested classes obey access rules just like other parts of a class do.And that class is a class enclosed within the scope of another class.
Ques: 139 What is an Iterator class?
Ans:
this class is used for traversing.
Its traverse through the objects maintained by a container class. Its have a five categories of iterators:
> input iterators
> output iterators
> forward iterators
> bidirectional iterators
> random access
Ques: 140 What is an incomplete type?
Ans:
Incomplete types :
> refers to pointers in which there is non availability of the implementation of the referenced location or it points to some location whose value is not available for modification.
Ques: 141 What is a dangling pointer?
Ans:
Dangling pointer occurs when we try to use the address of an object after its lift time is finished. This may occur in situations like returning addresses of the automatic variables from a function or using the address of the memory block after it is freed.
Ques: 142 Differentiate between the message and method
Ans:
Messages difines :
> Objects communicate by sending messages to each other.
> A message is sent to invoke a method.
Method desines :
> Provides response to a message.
> It is an implementation of an operation.
Ques: 143 What is class invariant?
Ans:
A class invariant is a bassicaly type of condiation .Its defines all valid states of an object. It ensures the proper working of class.
Ques: 144 What is stack unwinding?
Ans:
Stack unwinding is a type of a process. In this process like When an exception is thrown and control passes from a try block to a handler, the C++ run time calls destructors for all automatic objects constructed since the beginning of the try block. This process is called stack unwinding.
Ques: 145 What is a node class?
Ans:
A node class defines as :
> it relies on the base class for services and implementation.
> It provides a wider interface to the users than its base class.
> It relies primarily on virtual functions in its public interface.
> It depends on all its direct and indirect base class.
> It can be understood only in the context of the base class.
> It can be used as base for further derivation.
> It can be used to create objects.
A node class is a class that has added new services or functionality beyond the services inherited from its base class.
Ques: 146 What are proxy objects?
Ans:
Proxy object is a bassically that type of object which Objects that stand for other objects are called proxy objects or surrogates.
Ques: 147 Define namespace
Ans:
Namespaces is a bassically feature of C++. It is a relatively new C++ feature just now starting to appear in C++ compilers. We will be describing some aspects of namespaces in subsequent newsletters.
Ques: 148 What is an iterator class?
Ans:
An iterator class is bassically use for traversing. That are traverse through the objects maintained by a container class.
Ques: 149 When does a name clash occur?
Ans:
when we use a same name for all the classes
Ans:
when we use a same name for all the classes
Ans:
When we dont use "using namespace std;"
Ques: 150 What are the types of container classes?
Ans:
A container class bassically that class whihc is used to hold objects in memory or external storage. This class acts as a generic holder. It has a predefined behavior and a well-known interface. Its a type supporting class which mainly purpose is to hide the topology used for maintaining the list of objects in memory. When a
Container class contains a group of mixed objects, that tyme its called heterogeneous container; when the container is holding a group of objects that are all the same, that tyme its called homogeneous
Container.
Ques: 151 give me a diff b/e Template class and class Template?
Ans:
Many diff are there :
Template Class bassically a parameterized class not instantiated until the client provides the needed information. It�s jargon for plain templates. But in the Class template specifies how individual classes can be constructed much like the way a class specifies how individual objects can be constructed. It�s jargon for plain classes.
Ques: 152 wat do you mean by accessor?
Ans:
it is type of class operation, its does not modyfying the state of an object, these type of fuctions needs to be declare as a constant operation.
Ques: 153 What is a modifier?
Ans:
A modifier as a modifying function is a member function which changes the value of at least one
Data member. In other words, we can say an
Operation that modifies the stateof an object. Modifiers are also known as �mutators�.
Ques: 154 Explain the scope resolution operator?
Ans:
scope resolution operator permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.
Ques: 155 What are the access privileges in C++?
Ans:
C++ has three access privileges. They are private, public and protected.
Public- inherite the protected members as preotected in drived class and pubic members will be public in derived class.
Protected- pubic and protecated members of the base class will become protected in derived class
Private- pubilc and proteacted members will become private in derived class.
Ques: 156 What is the mean of Manglic in C++?
Ans:
Mangling is difine as :
> A C++ compiler generates function names that include an encoding of the function’s argument types. This is known as name mangling. There is no general standard for name mangling. Although all C++ compilers incorporate name mangling, no two do it the same way. We can avoid name mangling by declaring the functions as extern “C”; but
We can do this for only one of a set of functions with the same name .
Ques: 157 What is ‘this’ pointer?
Ans:
‘this’ pointer is a hidden member of a class or struct.It is bassicaly hidden parameter of non-static member functions. It is a pointer accessible only within the member functions of a class, structure, or union type.
Ques: 158 Declare a void pointer
Ans:
void pointer bassicaly used to store address of any type of variable. This is very useful when we want a pointer to point to data of different types at different times.
Ques: 159 How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?
Ans:
We have a three ways for declaring techniques :
1. Char *(*(*a[P])())(); 2. Build the declaration up in stages, using typedefs: Typedef char *pc; /* pointer to char */ Typedef pc fpc(); /* return function pointer to char */ Typedef fpc *pfpc; /* pointer to above */ Typedef pfpc fpfpc(); /* returning function */ Typedef fpfpc *pfpfpc; /* pointer to*/ Pfpfpc a[P]; /* array of*/ 3. Use the cdecl program, which turns English into C and vice versa: Cdecl> declare a as array of pointer to function returning pointer to function returning pointer to char Char *(*(*x[])())()
Ques: 160 What does extern mean in a function declaration?
Ans:
Extern is bassically significant only with data declarations. In the function declaration case, It can be used as a stylistic hint to indicate that the function’s definition is probably in
Another source file, but there is no formal difference
Between
Extern int A();
And Int A();
Ques: 161 What�s the best way to declare and define global variables?
Ans:
Best Way to represent a variable as global is – Just define the variable at the initial or just below the headers files. Though there can be many “declarations” of a single “global” variable or function, there must be exactly one “definition”. If a program is in several source files,the best arrangement is to place each definition
In some relevant source file, with an external declaration of function n variables in a seperate header file that is included by #include at the front of each source file.
Ques: 162 How do you decide which integer type to use?
Ans:
It depends on data which programmer want to use, it ups to the implementor to decide what it means to be
A fast integer type.
Ques: 163 Is there anything you can do in C++ that you cannot do in C?
Ans:
No. There is nothing you can do in C++ that you cannot do in C. After all you can write a C++ compiler in C
Ques: 164 Why do C++ compilers need name mangling?
Ans:
Name mangling is the rule according to which C++ changes function’s name into function signature before passing that function to a linker. This is how the linker differentiates between different functions with the same name.
Ques: 165 What issue do auto_ptr objects address?
Ans:
If you use auto_ptr objects you would not have to be concerned with heap objects not being deleted even if the exception is thrown.
Q33:Is there any problem with the following: Char *a=NULL; char& p = *a;? The result is undefined. You should never do this. A reference must always refer to some object.
Ques: 166 Can you think of a situation where your program would crash without reaching the breakball, which you set at the beginning of main()?
Ans:
C++ allows for dynamic initialization of global variables before main() is invoked. It is possible that initialization of global will invoke some function. If this function crashes the crash will occur before main() is entered.
Ques: 167 What happens when a function throws an exception that was not specified by an exception specification for this function?
Ans:
Unexpected() is called, which, by default, will eventually trigger abort().
Ques: 168 What is the difference between new/delete and malloc/free?
Ans:
Malloc/free do not know about constructors and destructors. New and delete create and destroy objects, while malloc and free allocate and deallocate memory.
Ques: 169 How do you know that your class needs a virtual destructor?
Ans:
If your class has at least one virtual function, you should make a destructor for this class virtual. This will allow you to delete a dynamic object through a baller to a base class object. If the destructor is non-virtual, then wrong destructor will be invoked during deletion of the dynamic object.
Ques: 170 When is a template a better solution than a base class?
Ans:
When you are designing a generic class to contain or otherwise manage objects of other types, when the format and behavior of those other types are unimportant to their containment or management, and particularly when those other types are unknown (thus, the generality) to the designer of the container or manager class.
Ques: 171 Explain the ISA and HASA class relationships. How would you implement each in a class design?
Ans:
A specialized class “is” a specialization of another class and, therefore, has the ISA relationship with the other class.
This relationship is best implemented by embedding an object of the Salary class in the Employee class
Ques: 172 How the compilers arranges the various sections in the executable image?
Ans:
The executable had following sections:-
Data Section (uninitialized data variable section, initialized data variable section )
Code Section
Remember that all static variables are allocated in the initialized variable section.
Ques: 173 What are the debugging methods you use when came across a problem?
Ans:
Debugging with tools like :
GDB, DBG, Forte, Visual Studio.
Analyzing the Core dump.
Using tusc to trace the last system call before crash.
Putting Debug statements in the program source code.
Ques: 174 n a constructor throw a exception? How to handle the error when the constructor fails?
Ans:
The constructor never throws a error.
Ques: 175 What is a virtual destructor?
Ans:
The simple answer is that a virtual destructor is one that is declared with the virtual attribute. The behavior of a virtual destructor is what is important. If you destroy an object through a baler or reference to a base class, and the base-class destructor is not virtual, the derived-class destructors are not executed, and the destruction might not be compile.
Ques: 176 When should you use multiple inheritance?
Ans:
There are three acceptable answers:- “Never,” “Rarely,” and “When the problem domain cannot be accurately modeled any other way.”
Consider an Asset class, Building class, Vehicle class, and CompanyCar class. All company cars are vehicles. Some company cars are assets because the organizations own them. Others might be leased. Not all assets are vehicles. Money accounts are assets. Real estate holdings are assets. Some real estate holdings are buildings. Not all buildings are assets. Ad infinitum. When you diagram these relationships, it becomes apparent that multiple inheritance is a likely and intuitive way to model this common problem domain. The applicant should understand, however, that multiple inheritance, like a chainsaw, is a useful tool that has its perils, needs respect, and is best avoided except when nothing else will do.
Ques: 177 What is the difference between a copy constructor and an overloaded assignment operator?
Ans:
A copy constructor constructs a new object by using the content of the argument object. An overloaded assignment operator assigns the contents of an existing object to another existing object of the same class.
Ques: 178 How many ways are there to initialize an int with a constant?
Ans:
1. Int f = 123; 2. Int bar(123);
Ques: 179 Explain the scope resolution operator?
Ans:
It permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.
Ques: 180 How do you link a C++ program to C functions?
Ans:
By using the extern “C” linkage specification around the C function declarations.
Programmers should know about mangled function names and type-safe linkages. Then they should explain how the extern “C” linkage specification statement turns that feature off during compilation so that the linker properly links function calls to C functions.
Ques: 181 Can inline functions have a recursion?
Ans:
No.
Syntax wise It is allowed. But then the function is no longer Inline. As the compiler will never know how deep the recursion is at compilation time.
Ques: 182 How Virtual functions call up is maintained?
Ans:
Through Look up tables added by the compile to every class image. This also leads to performance penalty.
Ques: 183 What is problem with Runtime type identification?
Ans:
The run time type identification comes at a cost of performance penalty. Compiler maintains the class.
Ques: 184 What about Virtual Destructor?
Ans:
Yes there is a Virtual Destructor. A destructor can be virtual as it is possible as at runtime depending on the type of object baller is balling to , proper destructor will be called.
Ques: 185 Is it possible to have Virtual Constructor? If yes, how? If not, Why not possible ?
Ans:
There is nothing like Virtual Constructor. The Constructor cant be virtual as the constructor is a code which is responsible for creating a instance of a class and it cant be delegated to any other object by virtual keyword means.
Ques: 186 How do I write code that reads data at memory location specified by segment and offset?
Ans:
Use peekb( ) function. This function returns byte(s) read from specific segment and offset locations in memory. The following program illustrates use of this function. In this program from VDU memory we have read characters and its attributes of the first row. The information stored in file is then further read and displayed using peek( ) function.
#include
#include
Main( ){
Char far *scr = 0xB8000000 ;
FILE *fp ;
Int offset ;
Char ch ;
If ( ( fp = fopen ( “scr.Dat”, “wb” ) ) == NULL )
{
Printf ( “\nUnable to open file” ) ;
Exit( ) ;
}
For ( offset = 0 ; offset < 160=”” ;=”” offset++=”” )=”” fprintf=”” (=”” fp,=”” “%c”,=”” peekb=”” (=”” scr,=”” offset=”” )=”” )=”” ;=”” fclose=”” (=”” fp=”” )=”” ;=”” if=”” (=”” (=”” fp=”fopen” (=”” “scr.Dat”,=”” “rb”=”” )=”” )=”=” null=”” )=”” {=”” printf=”” (=”” “\nunable=”” to=”” open=”” file”=”” )=”” ;=”” exit(=”” )=”” ;=”” }=”” for=”” (=”” offset=”0″ ;=”” offset=””>< 160=”” ;=”” offset++=”” )=”” {=”” fscanf=”” (=”” fp,=”” “%c”,=”” &ch=”” )=”” ;=”” printf=”” (=”” “%c”,=”” ch=”” )=”” ;=”” }=”” fclose=”” (=”” fp=”” )=”” ;=”” }=””>
Ques: 187 How do I know how many elements an array can hold?
Ans:
main( ){ Int i[32767] ; Float f[16383] ; Char s[65535] ; }
Ques: 188 Why doesn’t the following statement work? Char str[ ] = “Hello” ; Strcat ( str, ‘!’ )
Ans:
The string function strcat( ) concatenates strings and not a character. The basic difference between a string and a character is that a string is a collection of characters, represented by an array of characters whereas a character is a single character. To make the above statement work writes the statement as shown below:
Strcat ( str, “!” ) ;
Ques: 189 Why doesn’t the following code give the desired result?
Ans:
:int x = 3000, y = 2000 ; Long int z = x * y ; Ans:Here the multiplication is carried out between two ints x and y, and the result that would overflow would be truncated before being assigned to the variable z of type long int. However, to get the correct output, we should use an explicit cast to force long arithmetic as shown below: Long int z = ( long int ) x * y ; Note that ( long int )( x * y ) would not give the desired effect.
Ques: 190 What will be the output of the following code? Void main (){ Int i = 0 , a[3] ; A[i] = i++; Printf ("%d",a[i]) ; }
Ans:
The output for the above code would be a garbage value. In the statement a[i] = i++; the value of the variable i would get assigned first to a[i] i.E. A[0] and then the value of i would get incremented by 1. Since a[i] i.E. A[1] has not been initialized, a[i] will have a garbage value.
Ques: 191 What is Difference Between C/C++
Ans:
In C passing value to a function is “Call by Value” whereas in C++ its “Call by Reference”
2.C does not have a class/object concept.
C++ provides data abstraction, data encapsulation, Inheritance and Polymorphism.
3.C++ supports all C syntax.
File extension is .C in C while .Cpp in C++.(C++ compiler compiles the files with .C extension but C compiler can not!)
4.In C structures can not have contain functions declarations. In C++ structures are like classes, so declaring functions is legal and allowed.
C++ can have inline/virtual functions for the classes.
C++ is C with Classes hence C++ while in c the closest u can get to an User defined data type is struct and union.
Ques: 192 What is the difference between run time binding and compile time binding?
Ans:
Dynamic Binding:This is also known as “Late Binding”.The address of the functions are determined at runtime rather than at compile time.
Static Binding:This is also known as “Early Binding” .The address of the functions are determined at compile time rather than at run time.
Ques: 193 What is Operator overloading?
Ans:
When an operator is overloaded, it takes on an additional meaning relative to a certain class. But it can still retain all of its old meanings.
Examples:
1) The operators >> and < may=”” be=”” used=”” for=”” i/o=”” operations=”” because=”” in=”” the=”” header,=”” they=”” are=”” overloaded.=”” 2)=”” in=”” a=”” stack=”” class=”” it=”” is=”” possible=”” to=”” overload=”” the=”” +=”” operator=”” so=”” that=”” it=”” appends=”” the=”” contents=”” of=”” one=”” stack=”” to=”” the=”” contents=”” of=”” another.=”” but=”” the=”” +=”” operator=”” still=”” retains=”” its=”” original=”” meaning=”” relative=”” to=”” other=”” types=”” of=””>
Ques: 194 What is Smart Pointer?
Ans:
Its a bassicallly a objects which is store pointers to dynamically allocated objects. These pointers are seen as owning the object pointed to, And thus responsible for deletion of the object when it is no longer needed.Smart pointer is an abstract data type that simulates a pointer while providing additional features.
Ques: 195 What is the difference between a pointer and a reference?
Ans:
diff are there :
>References are aliases to variables , or we can say other name to a given variable, Even pointer holds the address of a particular variable.
> A Reference can be thought of as a special type of pointer with certain restrictions.
> We can create the array of Pointer but its not in case of reference.
> We can use pointer to pointer but we cnt us reference to referece.
> We can assign NULL to the pointer but in refencer we can’t.
> References have to be initialised at the time of declaration and cannot be changed in the code later , whereas this does’nt hold true with the pointer.
Ques: 196 What is importance of const. Pointer in copy constructor?
Ans:
Importance of copy constructor :
> Copy constructor is useful when an object is initialized with another existing object or an object is passed by value to a function or an object is returned by value from a function.
Ques: 197 What is a fake pointer?
Ans:
it is used to creat a illusion or vertual functianality of pointer,which is used to mutate the objects where single objects have multiple functionality at same time.
Ques: 198 What is the diffrence between static_cast and dynamic_cast in RTTI
Ans:
Static_cast from a base class pointer to a derived class pointer. It will do this properly for the up cast, And also properly for the downcast, If the object is actually a derived class. If the object wasn’t, we’ld get a pointer as if it were, but this might be very bad.
> RTTI is not an option and It is an embedded product. Therefore dynamic_cast is not an option.
Ques: 199 What do you mean by pure virtual functions?
Ans:
A pure virtual function is a bassically which function that must be overridden in a derived class and need not be defined. A pure virtual member function is a member function that the base class forces derived classes to provide. Any class containing any pure virtual function cannot be
Used to create object of its own type.
Ques: 200 What is virtual class and friend class?
Ans:
friend class is the bassically which class used when two or more classes are designed to work together.Used to share private data between 2 or
More classes the function declared as freind are not called using any object it is called like normal . But in virtual class is whihc class aids in multiple inheritance, it is used for run time polymorphism when object is linked to procedure call at run time.
Ques: 201 What is public, protected, private?
Ans:
Public variables – that are visible to all classes.
Private variables – that are visible only to the class to which they belong.
Protected variables – that are visible only to the class to which they belong, and any subclasses.
Ques: 202 What are Polymorphic Classes?
Ans:
polymorphic class declares or inherits a virtual function. A template class is nothing but a polymorphic class is – because it can work with different data-types, also under one name.
Ques: 203 Explain why encapsulation is required?
Ans:
Encapsulation bassically defined as :
> Encapsulation genral meaning is information hiding.
> The purpose of efficiency of memory and speed.
> The data and code binds together.
> It is an OOP principle of placing the data and functionality within a single entity.
> it is to protect data from the client using the classes but still allowing the client to access the data, but not modify it.
Ques: 204 What are the disadvantages of C++?
Ans:
Disadvantages:
> It’s not pure object oriented programming language.
> Its a Platform dependent
> C++ does not give excellant graphics as compare to java.
> Its Not case sensitive.
> C++ have Less features as comapred to Java& C#.
> Its Not applicable in web enviornment.
> Does not provide very strong type-checking.
> c++ code is easily prone to errors related to data types, their conversions.
> Does not provide efficient means for garbage collection.
> No built in support for threads.
Ques: 205 While copying the objects if we say X a=b, X a(b) What will it call, assignment operator or copy constructor? Justify
Ans:
Class check
{
Public: Int a,b;
Check ();
Check(const check&);
Check operator=(const check&);
Virtual ~check();
};
Check::check(const check& y) { Cout < “i=”” am=”” in=”” a=”” copy=””>;>< “i=”” am=”” using=”” assignment=”” operator=””>;>
Ques: 206 What is the difference between char str, char *str and char* str ?Explain the meaning of char* or int* ?
Ans:
Char *str is just a pointer its can’t store anything, If we cout or printf() char *str it prints till it finds termination char ”;
Char str is a char variable which is capable to store one character and store a string also. Its length can be fixed only at run time.Char* is pointer which store address of char variable .
Ques: 207 What are anonymous structure, unions and what are their uses?
Ans:
Anonymous unions are standard C++, and they can be found inside an object or inside a namespace. But Anonymous structures are not standard C++, therefore they are implemented as extensions.
Ques: 208 Why the size of empty Class is one byte?
Ans:
Everything must have a diff address in memory, otherwise there are very confusion with pointers. Hence even an empty class takes up one byte so the next thing we declare will have a different address.
Ques: 209 What is structure padding.Describe briefly?
Ans:
structure padding use for avoid the problems , We can use __attribute__(( xxxx )).Structure padding occurs because the structure members must appear at the correect byte boundary, to achieve this the compiler puts in padding bytes so that the structure members appear in the correct location.
Ques: 210 Why an empty Structure will occupy 2Bytes in C++
Ans:
Structure name assign a 1 byte from compiler side, spo Size of empty structure in C++ is 1 byte, Classes have no member that’s why objects have 0 bytes, However the objects must be legally creatable because the class is not abstract so there must be a way to address the objects.
Ques: 211 What is the compilation difference at the compiler level for C++, VC++ and C# ?
Ans:
The C++ compiler has the ability to produce both native and managed instructions.And VC++ is the Microsoft’s implementation of C++. Each C++ compiler might compile the code differently but in C# ompiles first into CIL (Common Intermediate Language) and then on runtime.
Ques: 212 What is operator overloading?What r the advantages of operator overloading?
Ans:
operator overloading is the property of Object oriented programming which gives an extra ability to an operator to act on a User-defined operand(Objects).
Advantages:
> It will act differently depending on the operands provided. Its called extesibility.
> It is not limited to work only with primitive Data Type.
> By using this overloading we can easily acces the objects to perform any operations.
> It makes code much more readable.
Ques: 213 Difference between a “assignment operator” and a “copy constructor”
Ans:
many diff are there :
> Copy constructor copies a existing object to a non existing object, which we are going to create. Assignment operator can happen between two existing objects.
> copy constructor creates shallow copy assignment operator creates deep copy.
> Assignment operator assign the value of one object to another aftr the 1st object is fully created but in copy constructor it assign the value of one object to another at the time of its creation.
> Copy constructor donot return anything. Assignment operator returns object of same type.
> Copy constuctor initialize the object with the another object of same class whereas assignment operator can be called on objects of different classes .
Ques: 214 What is namespace?
Ans:
Namespaces bassically provide a simple method for qualifying element and attribute names used in Extensible Markup Language documents by associating them with namespaces identified by URI references. Its allow to group entities like classes, objects and functions under a name. This way the global scope can be divided in “sub-scopes”, each one with its own name. It is an abstract container providing context for the items. It holds and allowing disambiguation of items having the same name.
Ques: 215 What is a scope resolution operator?
Ans:
Scope Resolution Operator is defined as (::). It used to define the member functions of a class outside the class. It shows the scope resolution operator untangling a mess made by using
The same names for different kinds of entities. It resolves global scope to local scope.
Ex:
Int x=20;
Int main()
{
X=30;
Cout<>;><>;><>;>
Ques: 216 What is the use of new operator?
Ans:
In C++ New Operator used to allocate the memory for the object on HEAP. It allocates the memory of size equal to the object of size, The new operator will return NULL or throw an exception on failure.
It provides dynamic storage allocation. Its syntax for an allocation expression containing the new operator is:
>>-+—-+–new–+———————+–+-(–type–)-+———> ‘-::-‘ ‘-(–argument_list–)-‘ ‘-new_type—‘ >–+————————-+———————————>< ‘-(–+—————+–)-‘=”” ‘-initial_value-‘=””>
Ques: 217 What was the most difficult debug you have ever done?
Ans:
whenever any application get hanged, & we don’t know even from wherewe should start debuging….This can be the most difficult .
Ques: 218 How will you detect if there is memory leak in your C++ program?
Ans:
Some time before we have got a some problem of detecting memory leaks in our code, and we didn’t afforrd the rates of a brittle software package to do that. It’s fairly simple to redefine malloc() and free() to your own functions, to track the file and line number of memory leaks. But what about the new() and delete() operators? It’s a little more difficult with C++, if we want to figure out the exact line number of a resource leak.
If we are using new and delete operator, We can overload both the operators and can count number off heap allocation and deallocation. You can also get the __FILE__ and __LINE__ to get to know the file name and line number. Now the new and delete of a memory location should be in pair and if its not there is a memroy leak. By using line and file utility you can reach upto the exact location.
Ques: 219 What is the difference between block structured language and highly block structured language
Ans:
Block Structure Langguage Bassically a normal programming language in which sections of source code contained within pairs of matching delimiters such as “” and “” (e.G. In C) or “begin” and “end” (e.G. Algol) are executed as a single unit. Its A class of high-level languages in which a program is made up of blocks � which may include nested blocks as components, such nesting being repeated to any depth.
Ques: 220 What happens to the member function in the class when copy constructor is invoked?
Ans:
First of all we want to tell you that only the member function have the athourity to invoke any other member function.But cunstructor have a diff property, is that it used to initialise the values to data members. And they are constant and it cannot be invoked any other constuctor. If they are copied compiler should not understand or didnot diffrentiate that what is member function and what is constructor, so ambiquity will be raised.
Ques: 221 What is RTTI?
Ans:
RTTI bassicaly Run Time Type Information. It Certain language features to work a limited amount of information about types is required at runtime. This is the Run Time Type Information or RTTI.
Ques: 222 What are virtual functions?
Ans:
virtual functionsdefines as :
> C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. The whole function body can be replaced with a new set of implementation in the derived class.
> A virtual function is a member function which we may redefine for other derived classes, And can ensure that the compiler will call the redefined virtual function for an object of the corresponding derived class, Even if we call that function with a pointer or reference to a base class of the object.
> A virtual function is a member function of a class, which functionality can be over-ridden in its derived classes. It is one that is declared as virtual in the base class using the virtual keyword.
> C++ virtual function properties are:
* A member function of a class.
* Declared with virtual keyword.
* Usually has a different functionality in the derived class.
* A function call is resolved at run-time.
Ques: 223 What is the difference between far pointer and near pointer?
Ans:
Many diff are there :
> A normal pointer can only point to the main memory location, But the far pointer can have an address of any location of ur memory even seconday one also.
> A far pointer is used to access a location which is outside current segment.
> Near pointers are fully recognised and evaluated for their entire width. But in Far pointers only allow normal operations to be done to their offset amount and not the segment or paragraph amount.
Ques: 224 What is difference between visual c++ & ANSI c++ ?
Ans:
Visual C++ is probably the most popular favored compiler, because of it’s history of quality and stablity.But in ANSI C++ is a less popular, but is a much more powerful and robust compiler. The IDE is also a lot more powerful than MSVC.
Ques: 225 What is the advantage of function overloading according to users point of view?
Ans:
We know that function name is same. But each time we are writing code for each function. In this case it is advantageous than normal function.
Ans:
waste site
Ques: 226 Difference between a “assignment operator” and a “copy constructor”
Ans:
many diff are there : > Assignment operator assign the object of one object to another aftr the 1st object is fully created but in copy constructor it Assign the value of one object to another at the time of its creation . > The copy constructor is use for initialising a new instance from an old instance, And is called when passing variables by value into functions Or as return values out of functions. But in Assignment operator is used to change an existing instance to have the same values as the rvalue, which means that the instance has to be destroyed and re-initialized if it has internal dynamic memory. > Copy constructor copies a existing object to a non existing object, which we are going to create. Assignment operation can happen between two existing objects. > The copy constructor is creating a new object. But in The assignment operator has to deal with the existing data in the object. > Copy constructor creates shallow copy but in assignment operator creates deep copy. > The copy constructor is called at initialising the object but the assignment operator is used to assign one object to another. > Copy constructor donot return anything. But in Assignment operator returns object of same type. > The copy constructor initializes uninitialized memory, But in assigenment operator starts with an existing initialized objects. > Copy constuctor initialize the object with the another object of same class But assignment operator can be called on objects of different classes .
Ques: 227 What is the difference between “overloading” and “overriding”?
Ans:
Many Diffreces are there-
Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.
Overridding is runtime polymorphism while overloading is compile time polymorphism.
Ques: 228 Difference between “C structure” and “C++ structure”
Ans:
Many diff are there :
>Structure in C defines as limited to within the module and cannot be initialized outside but Structure in C++ can initialize the objects anywhere within the boundaries of the project.
> C++ have a many methods((Procedures) but in C no methods are there.
> By default C structure are Public and C++ structure are private .
> C does not support Methods inside structure but C++ does.
> In C++ structure we can add functions but in C
Structure we can’t.
> In C++, structure behaves like class like can add function, and can use properties on class as inheritance, virtual,etc, But in C, structure we can have only data member but not functions.
> Structures in c++ doesnot provide datahiding but a class provides.
> classes support polymorphism, But Structures don’t.
Ques: 229 What is the difference between operator new and the new operator?
Ans:
Many diff are there :
Operator new is bassically just like malloc and new is the conventinally new in C++. The “New” operator allocates a new instance of an object
From the heap, Its utilising the most appropriate constructor for the arguments passed. This is Like many operators in C++, The “New” operator for a
Particular class can be overriden, Although there is rarely a need to do so. “Operator new” is the mechanism for overriding the default heap allocation logic.
Ans:
Operator new() use for the Operator overloading but New Operator for memory allocation.
Ques: 230 What is virtual constructors/destructors?
Ans:
virtual constructors/destructors : Virtual destructors It is a Bassically same as vertual fuction, Its commonly used with inheritance. Since an abstract class must contain a pure virtual method that has to be overridden, a lot of developers commonly declare their destructors pure virtual, since a destructor is sure to be implemented in every subclass.
Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error. There is no virtual constructor coz virtual thing is in run time n constructor is compile time thing.
Ques: 231 What is a template?
Ans:
Templates is defined as :
> It is a framework for web pages and sites.
> Its type of model or standard for making comparisons.
> It is a feature of the C++ programming language its allow functions and classes to be operate with generic types.
> It is a tool for enforcing a standard layout and look and feel across multiple pages or within content regions.
> Its a model or pattern used for making multiple copies of a single object.
Ques: 232 Difference between realloc() and free()?
Ans:
Diff b/w realloc() and free():
Realloc():
> It is used to free the memory in the program.
> This function is used to resize memory.
> realloc() means it giving string variables into the existed memory
Free():
> Basically It is a macro. Macro used to deallocate memory.
> free() function is used free the memory which is allocated by malloc(),calloc() functions.
> free() means it empties the array.
Ques: 233 What is the difference between an object and a class?
Ans:
Class and Objects are diff but related concepts. Every objects belogs to the class and evry class have a one or more related objets.
Class are: > A Class is static. > A class combination of data(called data members)and functions(called member functions). > Class is a userdefined datatype with data members and member functions. > Classe defines object. > One class can define any no of Object. > Class is a template(type) or blue print its state how objects should be and behave. Object are: > Object is an instance of a class while a class can have many objects. > Object is a dynamic. > Objects are the basic runtime entities in an object oriented sysyem. > Data and function which combine into a single entity is called object. > Objects are instances of classes which identifies the class propeties. > Object can’t define classes. > Object can created and destroyed as your necessity. > Object is defined as a s/w construct which binds data and logic or methods(functions) both.
Ques: 234 What is the difference between class and structure?
Ans:
Diff b/w Class and Structure is :
Class is difined as-
>Class is a successor of Structure. By default all the members inside the class are private.
>Class is the advanced and the secured form of structure.
>Classes are refernce typed.
>Class can be inherited.
>In Class we can initilase the variable during the declaration.
>Class can not be declared without a tag at the first time.
>Class support polymorphism.
Structure difine as :
> In C++ extended the structure to contain functions also. All declarations inside a structure are by default public.
> Structures contains only data while class bind both data and member functions.
> Structure dosen’t support the polymorphism, inheritance and initilization.
> Structure is a collection of the different data type.
> Structure is ovrloaded.
> Structures are value type.
> Structure can be declared without a tag at the first time
Ques: 235 Question : What is the difference between parameter and argument?
Ans:
Diff b/w parameter and argument is :
Argument bassically is one of the following –
> An Expression in the comma-separated list in a function call.
> A sequence of one or more preprocessor tokens in the comma-separated list in a macro call.
> Its represent the value which you pass to a procedure parameter when you call the procedure. The calling code supplies the arguments when it calls the procedure.
> It is something passed into a function(value), whereas a parameter is the type of data plus the name.
Parameter bassically is one of the following –
> An object that is declared in a function declaration or definition.
> An identifier b/w the parentheses immediately following the macro name in a macro definition.
> It is represent a value that the procedure expects you to pass when you call it. The procedure’s declaration defines its parameters.
This example explains the difference b/w a parameter and an argument:
Void function(int x, char * rs); //x and rs are parameters Template class M {}; //Tem is a parameter
Int main()
{
Char c;
Char *p = &c;
Func(5, p); //5 and p are arguments
M a; //’long’ is an argument
M another_a; //’char’ is an argument
Return 0;
}