Interview Questions.

Top 100+ Infosys C++ Interview Questions And Answers


Top 100+ Infosys C++ Interview Questions And Answers

Question 1. What Is Virtual Constructors/destructors?

Answer :

Virtual destructors: If an item (with a non-virtual destructor) is destroyed explicitly by making use of the delete operator to a base-elegance pointer to the item, the base-elegance destructor feature (matching the pointer type) is referred to as at the object.

There is a simple way to this problem – claim a virtual base-magnificence destructor. This makes all derived-class destructors digital despite the fact that they don’t have the same call because the base-magnificence destructor. Now, if the item within the hierarchy is destroyed explicitly by using making use of the delete operator to a base-elegance pointer to a derived-elegance object, the destructor for the suitable elegance is called.

Virtual constructor: Constructors can't be digital. Declaring a constructor as a virtual characteristic is a syntax mistakes. Does c++ assist multilevel and a couple of inheritance.

Question 2. Why Garbage Collection?

Answer :

Since C++ does now not provide computerized rubbish collection like some different languages, clever recommendations may be used for that cause. The best garbage series scheme is reference counting or reference linking, however it's miles pretty possible to enforce more state-of-the-art rubbish series schemes with smart recommendations.

DBMS Interview Questions
Question three. How To Write A Swap( ) Function Which Swaps The Values Of The Variables Using Bitwise Operators.?

Answer :

Here is the swap( ) characteristic.

Change ( int *x, int *y )

*x ^= *y ;

*y ^= *x ;

*x ^= *y ;

The switch( ) function makes use of the bitwise XOR operator and does not require any brief variable for swapping.

Question four. What Are The Advantages Of Inheritance?

Answer :

It permits code reusability.
Reusability saves time in software improvement.
It encourages the reuse of confirmed and debugged incredible software program, as a consequence reducing trouble after a system turns into purposeful.
C++ Tutorial
Question 5. What Is The Difference Between Declaration And Definition?

Answer :

The declaration tells the compiler that at a few later factor we plan to present the definition of this announcement.

E.G.: void stars () //feature declaration

The definition consists of the actual implementation.

E.G.: void stars () // declarator

for(int j=10; j>=0; j--) //function frame

cout<<”*”; cout< function_declaration; template


The only distinction between each prototypes is the usage of key-word magnificence or typename, its use is

indistinct because both expressions have exactly the same which means and behave exactly the identical manner.

C++ Interview Questions
Question 6. What Do You Mean By Inline Function?

Answer :

The idea at the back of inline features is to insert the code of a known as feature at the factor where thefunction is called. If achieved carefully, this may enhance the utility'sperformance in alternate for expanded assemble time and probably (however not continually) an boom in the size of the generated binary executables.

Question 7. What Is Virtual Class And Friend Class?

Answer :

Friend lessons are used whilst  or extra classes are designed to paintings together and need get entry to to each different's implementation in ways that the rest of the world shouldn't be allowed to have. In other words, they help maintain private things personal. For instance, it may be acceptable for class DatabaseCursor to have more privilege to the internals of sophistication Database than principal() has.

C#. NET Tutorial C#. NET Interview Questions
Question eight. What Is Function Overloading And Operator Overloading?

Answer :

Student Resources Function overloading: C++ enables several features of the same call to be described, as long as these capabilities have unique sets of parameters (at least as some distance as their types are worried). This capability is referred to as characteristic overloading. When an overloaded function is called, the C++ compiler selects the proper function by way of analyzing the number, sorts and order of the arguments in the name.

Function overloading is generally used to create numerous capabilities of the identical name that perform comparable obligations but on one of a kind records sorts.

Operator overloading lets in existing C++ operators to be redefined so that they work on objects

of user-defined instructions. Overloaded operators are syntactic sugar for equivalent feature calls. They shape a pleasing facade that does not add something essential to the language (but they could enhance understandability and decrease upkeep expenses).

Question nine. Difference Between Realloc() And Free()?

Answer :

The free subroutine frees a block of memory previously allotted by the malloc subroutine.

Undefined effects occur if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null price, no movement will occur. The realloc subroutine modifications the size of the block of memory pointed to by using the Pointer parameter to the range of bytes distinct via the Size parameter and returns a brand new pointer to the block. The pointer distinct by using the Pointer parameter should were created with the malloc, calloc, or realloc subroutines and not been deallocated with the unfastened or realloc subroutines. Undefined effects arise if the Pointer parameter isn't a valid pointer

Core Java Interview Questions
Question 10. What Do You Mean By Binding Of Data And Functions?

Answer :


Core Java Tutorial
Question eleven. What Is Abstraction?

Answer :

Abstraction is of the system of hiding undesirable information from the user.

Data Structures Interview Questions
Question 12. What Is Encapsulation?

Answer :

Packaging an item’s variables within its techniques is known as encapsulation.

DBMS Interview Questions
Question 13. What Is The Difference Between An Object And A Class?

Answer :

Classes and items are separate however related principles. Every item belongs to a category and every elegance carries one or extra associated gadgets.

A Class is static. All of the attributes of a category are fixed earlier than, in the course of, and after the execution of a software. The attributes of a category don't exchange.
The elegance to which an item belongs is also (commonly) static. If a selected object belongs to a positive elegance at the time that it is created then it nearly really will nonetheless belong to that class right up until the time that it is destroyed.
An Object on the other hand has a limited lifespan. Objects are created and finally destroyed. Also at some stage in that lifetime, the attributes of the item may also go through giant trade.
Data Structures Tutorial
Question 14. What Is Polymorphism? Explain With An Example?

Answer :

"Poly" method "many" and "morph" way "form". Polymorphism is the potential of an object (or reference) to expect (get replaced with the aid of) or come to be many special sorts of item.

Example: function overloading, feature overriding, digital features. Another instance can be a plus ‘+’ signal, used for adding  integers or for using it to concatenate two strings.

Question 15. What Do You Mean By Inheritance?

Answer :

Inheritance is the technique of making new instructions, called derived training, from current classes or base lessons. The derived magnificence inherits all the competencies of the bottom class, however can upload elaborations and refinements of its personal.

C & Data Structures Interview Questions
Question 16. What Is A Scope Resolution Operator?

Answer :

A scope resolution operator (::), can be used to define the member capabilities of a category out of doors the elegance.

Java Tutorial
Question 17. What Are Virtual Functions?

Answer :

A virtual feature allows derived training to replace the implementation furnished by way of the base magnificence. The compiler makes certain the substitute is usually called whenever the object in question is virtually of the derived magnificence, despite the fact that the object is accessed through a base pointer as opposed to a derived pointer. This allows algorithms in the base elegance to get replaced in the derived elegance, although users don't know about the derived class.

ADO.Net Interview Questions
Question 18. What Is Friend Function?

Answer :

As the name suggests, the characteristic acts as a chum to a category. As a pal of a category, it is able to access its personal and guarded participants. A friend characteristic isn't a member of the elegance. But it should be listed within the elegance definition.

C++ Interview Questions
Question 19. What Is The Difference Between Class And Structure?

Answer :

Structure: Initially (in C) a shape became used to package deal exceptional kind of facts types collectively to carry out a particular capability. But C++ extended the structure to include capabilities additionally. The main difference is that all declarations inside a shape are by means of default public.

Class: Class is a successor of Structure. By default all the members within the class are non-public.

Go (programming language) Tutorial
Question 20. What Is Public, Protected, Private?

Answer :

Public, covered and personal are three access specifiers in C++.
Public records members and member features are reachable outside the class.
Protected data participants and member functions are best available to derived instructions.
Private data members and member functions can’t be accessed out of doors the magnificence.
However there's an exception can be the use of pal training.

Java Interview Questions
Question 21. What Is An Object?

Answer :

Object is a software package deal of variables and associated methods. Objects have nation and conduct.

Question 22. What Is A Class?

Answer :

Class is a person-described statistics kind in C++. It can be created to remedy a selected sort of problem.

After advent the user need now not understand the specifics of the working of a class.

F Sharp (programming language) Tutorial
Question 23. When Linking C Or Assembly Language Modules With C++ Modules I Get Undefined Symbol Errors At Link Time. It Appears That None Of The C Or Assembly Public Symbols Can Be Found.?

Answer :

C++ is a strongly typed language. In order to assist the language to its fullest, Turbo C++ ought to connect statistics to the symbols generated for feature names and variables. When this is completed, the image will now not healthy the usual C fashion function call. In order to hyperlink correctly, the compiler have to be notified that the symbol is declared in an outside module without type records tacked on to the symbol. This is carried out by way of prototyping the feature as kind extern "C". Here is a short instance: extern "C" int normal_c_func( waft, int, char ); // call not altered void cplusplus_function( int ); // name altered .

Go (programming language) Interview Questions
Question 24. Classes With Static Data Members Are Getting Linker Errors ("undefined").?

Answer :

This code is constructed into Turbo C++ 1.Zero but no longer in version 3.0. In the 1.Zero compiler, static participants with out definitions were given a default cost of 0. This default definition will no longer be made inside the compiler. The programmer must now deliver an specific definition for every static member.

Here is a short example: 

elegance A 


static int i; 

A linker blunders saying that A::i is not described will result except the source additionally includes a line such as: 

int A::i = 1;

C#. NET Interview Questions
Question 25. What Potential Problems Can Arise From Type Casting A Base Class Pointer Into A Derived Class Pointer So That The Derived Class's Member Functions Can Be Called?

Answer :

Syntactically that is allowable. There is constantly the opportunity of a base pointer really pointing to a base class. If that is typecast to a derived type, the approach being called may not exist inside the base class. Therefore, you will be grabbing the address of a characteristic that doesn't exist.

R Programming language Tutorial
Question 26. What's The Difference Between The Keywords Struct And Class?

Answer :

The contributors of a STRUCT are PUBLIC by using default, at the same time as in CLASS, they default to PRIVATE. They are in any other case functionally equal.

F Sharp (programming language) Interview Questions
Question 27. I Have Declared A Derived Class From A Base Class, But I Can't Access Any Of The Base Class Members With The Derived Class Function.?

Answer :

Derived training DO NOT get get admission to to personal participants of a base class. In order to get admission to members of a base class, the base class participants need to be declared as either public or covered. If they are public, then any portion of this system can get admission to them. If they're included, they are on hand by means of the class participants, buddies, and any derived lessons.

Core Java Interview Questions
Question 28. How Can I Use The Paradox Engine 1.Zero With C++?

Answer :

Because the Paradox Engine functions are all compiled as C features, you'll should guarantee that the names of the features do not get "mangled" through the C++ compiler. To do this you want to prototype the Engine features as extern "C". In the pxengine.H header file insert the following code on the lines indicated. 

/* inserted at line # 268 */ 

#ifdef __cplusplus 

extern "C"  


/* inserted at line # 732, just earlier than the final #endif */ 

#ifdef __cplusplus 


Paradox Engine model 2.0 is "conscious" of C++ and hence does not require any adjustments to its header file.

D Programming Language Tutorial
Question 29. I Have A Class That Is Derived From Three Base Classes. Can I Insure That One Base Class Constructor Will Be Called Before All Other Constructors?

Answer :

If you declare the bottom class as a virtual base elegance, its constructor might be referred to as before any non-virtual base elegance constructors. Otherwise the constructors are known as in left-to-proper order on the statement line for the magnificence.

C preprocessor Interview Questions
Question 30. Are The Standard Library I/o Functions Still Available For Use With The C++ Iostreams Library?

Answer :

Yes, the use of 


features along with printf() and scanf() will stay available. However, the use of them at the side of move oriented features can result in unpredictable behaviour.

Question 31. In C++, Given Two Variables Of The Same Name, One Local And One Global, How Do I Access The Global Instance Within The Local Scope?

Answer :

Use the scope (::) operator. 

Int x = 10; 

for(int x=zero; x < ::x; x++) 


cout << "Loop # " << x << "n"; // This will loop 10 instances 

Question 32. Will The Following Two Functions Be Overloaded By The Compiler, Or Will The Compiler Flag It As An Error? Why? Void Test( Int X, Double Y); & Int Test( Int A, Double B).

Answer :

The compiler will flag this as a redeclaration errors due to the fact neither return kinds nor argument names are considered while determining precise signatures for overloading capabilities. Only variety and type of arguments are considered.

R Programming language Interview Questions
Question 33. If I Pass A Character To A Function Which Only Accepts An Int, What Will The Compiler Do? Will It Flag It As An Error?

Answer :

No. The compiler will sell the char to an int and use the integer representation in the characteristic as opposed to the character itself.

Data Structures Interview Questions
Question 34. I Was Trying To Allocate An Array Of Function Pointers Using The New Operator But I Keep Getting Declaration Syntax Errors Using The Following Syntax: New Int(*[10])(); What's Wrong?

Answer :

The new operator is a unary operator and binds first to the int key-word generating the following: (new int) (*[10])(); 

You need to position parentheses across the expression to provide the expected consequences: new (int (*[10]());

Question 35. What Are Inline Functions? What Are Their Advantages? How Are They Declared?

Answer :

An inline function is a characteristic which receives textually inserted by the compiler, much like macros. The benefit is that execution time is shortened due to the fact linker overhead is minimized. They are declared by means of using the inline keyword when the characteristic is declared: 

inline void func(void)  cout << "printing inline characteristic n";  

or by means of consisting of the feature assertion and code frame within a class: 

class check 


television public: 

void func(void)  cout << "inline function inside a category.N" 


Question 36. If I Don't Specify Either Public Or Private Sections In A Class, What Is The Default?

Answer :

In a class, all members are personal by way of default if neither public nor non-public sections are declared.

C & Data Structures Interview Questions
Question 37. What Does The _seg Modifier Do?

Answer :

Using _seg reasons a pointer to emerge as a storage place for a section value, rather than an offset ( or a phase/offset ). For instance, if "int _seg *x" incorporates the cost 0x40, then when you operate "*x", the fee pointed to could be at segment 0x40, offset 0. If you upload a price to the pointer, the value is accelerated by way of the size of the pointer kind. That new cost is used as an offset, and is combined with the phase cost contained inside the pointer. For example, 

int _seg *x; 

int price; 

x = (int _seg *)0x40; 

value = *(x + 20); 

value is assigned the fee of the integer at 0x40:0x28 

(Remember, 20 * sizeof(int) = 40 = 0x28).

Question 38. Can I Statically Allocate More Than 64k Of Data In A Single Module?

Answer :

Yes. Far facts gadgets are actually supported: 


Char some distance array1[60000L]; 

char some distance array2[60000L]; 


For arrays large than 64k use: 

char huge array3[100000L];

Question 39. What Is A Friend Member Function?

Answer :

Declaring a friend offers non-individuals of a category access to the personal contributors of a class.

Question 40. Why Do I Get A "kind Name Expected" Error On My Definition Of A Friend Class In My New Class?

Answer :

A You need to allow the compiler know that the label you use in your friend class is every other magnificence. If you do no longer want to define your whole magnificence, you can really have "class xxx", in which xxx is your label.

ADO.Net Interview Questions
Question 41. How Can I Output Hex Values In Upper Case Using The Iostream Libraries?

Answer :

You want to set the country of the move the use of setf(). For example, 

#consist of 

int important(void) 


cout << hex; 

cout << "nNot higher-case : " << 255; 


cout << "nUppercase : " << 255; 

return 0; 

Question 42. What Is The "this" Pointer?

Answer :

"this" is a local variable in the body of a non-static member function. It is a pointer to the object for which the function was invoked. It cannot be used outside of a class member function body.

Java Interview Questions
Question 43. Why Does A Binary Member Function Only Accept A Single Argument?

Answer :

The first argument is defined implicitly.

Question 44. What Is The Const Keyword Doing Here?

Answer :

There is a pointer to the object for which a function is called known as the 'this' pointer. By default the type of 'this' is X *const ( a constant pointer). The const keyword changes the type to const X *const ( a constant pointer to constant data ).

Question 45. I Want To Use _new_handler And Set_new_handler.

Answer :

Turbo C++ supports _new_handler and set_new_handler.

The type of _new_handler is as follows:

typedef void (*vfp)(void); 

vfp _new_handler; 

vfp set_new_handler( vfp );

Question 46. I Would Like To Use C++ Fstreams On A File Opened In Binary Mode, How Is This Done?

Answer :

Use ios::binary as the open mode for the file: 


ifstream binfile; 

binfile.Open("myfile.Bin", ios::binary);

Question 47. How Can I Get At The Dos File Handle Associated With My Iostream?

Answer :

Using a combination of member functions fd() and rdbuf() you can get at the file handle. 


#define fstrno(s) (((s).Rdbuf())->fd()) 

ifstream test("take a look at.Txt"); 

cout << "manage is " << fstrno(test) << 'n';