October 12, 2018

Sreekanth B

ThoughtWorks Most Frequently Asked C++ Interview Questions Answers

What Is The Difference Between Realloc() And Free()?

The free subroutine frees a block of memory previously allocated by the malloc subroutine. Undefined results occur if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null value, no action will occur.

The realloc subroutine changes the size of the block of memory pointed to by the Pointer parameter to the number of bytes specified by the Size parameter and returns a new pointer to the block. The pointer specified by the Pointer parameter must have been created with the malloc, calloc, or realloc subroutines and not been deallocated with the free or realloc subroutines. Undefined results occur if the Pointer parameter is not a valid pointer.

What Is Function Overloading And Operator Overloading?

Function overloading: C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are 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 allows existing C++ operators to be redefined so that they work on objects of user-defined classes. Overloaded operators are syntactic sugar for equivalent function calls. They form a pleasant facade that doesn't add anything fundamental to the language (but they can improve understandability and reduce maintenance costs).
ThoughtWorks Most Frequently Asked C++ Interview Questions Answers
ThoughtWorks Most Frequently Asked C++ Interview Questions Answers

What Is The Difference Between Declaration And Definition?

The declaration tells the compiler that at some later point we plan to present the definition of this declaration.
E.g.: void stars () //function declaration
The definition contains the actual implementation.

void stars () // declarator
for(intj=10;j > =0;j—) //function body
cout« endl; }

What Are The Advantages Of Inheritance In C++?

It permits code reusability. Reusability saves time in program development. It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system becomes functional.

How Do You Write A Function That Can Reverse A Linked-list?

void reverselist(void)
head->next = 0;
tail->next = head;
}  else
node* pre = head;
node* cur = head->next;
node* curnext = cur->next;
head->next = 0; cur-> next = head;
for(; curnext !=0;)
cur->next  = pre;
pre  = cur;
cur  = curnext;
curnext = curnext->next;
curnext->next = cur;

What Do You Mean By Inline Function?

The idea behind inline functions is to insert the code of a called function at the point where the function is called. If done carefully, this can improve the application's performance in exchange for increased compile time and possibly (but not always) an increase in the size of the generated binary executables.

Write A Program That Ask For User Input From 5 To 9 Then Calculate The Average?

#include  "iostream.h" intmain()
intMAX = 4;
int total = 0;
int average; int  numb;
for  (int i=0; KMAX; i++) {
"Please  enter your input between 5 and 9: ";
cin  » numb;
while  (numb<5 || numb>9) {
cout« "Invalid input, please re-enter: ";
cin  » numb;
total = total + numb;
average  = total/MAX;
cout« "The average number is: "
« average « "n";
 return 0;

Write A Short Code Using C++ To Print Out All Odd Number From 1 To 100 Using A For Loop

for( unsigned int i = 1; i < = 100; i++ )
if( l & 0x00000001 )

What Is Public, Protected, Private In C++?

Public, protected and private are three access specifiers in C++.
Public data members and member functions are accessible outside the class.
Protected data members and member functions are only available to derived classes.
Private data members and member functions can't be accessed outside the class. However there is an exception can be using friend classes.

Write A Function That Swaps The Values Of Two Integers, Using Int* As The Argument Type?

void swap(int* a, int*b)
*a = *b;
*b = t;

What Is Virtual Constructors/destructors?

Virtual destructors: If an object (with a non-virtual destructor) is destroyed explicitly by applying the delete operator to a base-class pointer to the object, the base-class destructor function (matching the pointer type) is called on the object. There is a simple solution to this problem declare a virtual base-class destructor.

This makes all derived-class destructors virtual even though they don't have the same name as the base-class destructor. Now, if the object in the hierarchy is destroyed explicitly by applying the delete operator to a base-class pointer to a derived-class object, the destructor for the appropriate class is called. Virtual constructor: Constructors cannot be virtual. Declaring a constructor as a virtual function is a syntax error.

What Is The Difference Between An Array And A List?

Array:  is collection of homogeneous elements.
List :is collection of heterogeneous elements.
 Array: memory allocated is static and continuous.
 List:  memory allocated is dynamic and Random.
Array:  User need not have to keep in track of next memory allocation.
List:  User has to keep in Track of next location where memory is allocated.

Does C++ Support Multilevel And Multiple Inheritance?


Subscribe to get more Posts :