- World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.

Get it now !!
Send your Resume to 6000 Companies
Arrays, Strings, Pointers and References in C++ Interview Questions & Answers - Learning Mode

Arrays, Strings, Pointers and References in C++ Interview Questions & Answers - Learning Mode

Arrays in C++ An array is a data structure which allows a collective name to be given to a group of elements which all have the same type. An individual element of an array is identified by its own unique index (or subscript). An array can be thought of as a collection of numbered boxes each containing one data item. C++ provides a simple, safe alternative to using char*s to handle strings. The C++ string class, part of the std namespace, allows you to manipulate strings safely. Declaring a string is easy: using namespace std; string my_string;

Try Arrays, Strings, Pointers and References in C++ Interview Questions & Answers - Exam Mode

1 2 3 Next

Sort By : Latest First | Oldest First | By Rating

Arrays, Strings, Pointers and References in C++ Interview Questions & Answers - Learning Mode
Try Arrays, Strings, Pointers and References in C++ Interview Questions & Answers - Exam Mode
Question: Difference between stack memory and heap memory?

Answer: Stack = region of memory for temporaries
Stack pointer pushed on function entry
Popped on function exit
Stack data: new every time
stack is used for local variables
Heap = distinct region of memory for persistent objects
Allocate persistent data on heap with new keyword
Dynamically allocated memory (heap)exists until it is released either explicitly by the programmer
C/C++ ? explicitly managed
Question: What is importance of const. pointer in copy constructor?

Answer: Because otherwise you will pass the object to copy as an argument of copy constructor as pass by value which by definition creates a copy and so on... an infinite call chain....Do you see that-Prashant Source:
Question: Define a class to represent a bank account. In the class, include the following members:
Data members: name of the depositor, account number, type of account, and balance amount in the account.
Member functions: to assign initial values, to deposit an amount, to withdrawal an amount after checking the balance, and to display the name and balance.
Write main() code to test your class?

Answer: #include<iostream.h>

// statement of customer detail....

struct acc_data
char c_name[25];
int acc_no;
float balance;
char acc_type[2];


//statement of Class....

class bank
struct acc_data x;
void input();
void withdrawal(int,float);
void deposit(int,float);
void display(int);


// Statement o Source:
Question: Why always array starts with index 0?

Answer: Array name is a constant pointer pointing to the base address(address of the first byte where the array begin) of the memory allocated. When you use arr[i], the compiler manipulates it as *(arr + i). Since arr is the address of the first element, the value of i must be 0 for accessing it. Hence all arrays begin with an index of 0. Source:
Question: What is "strstream??

Answer: Class that reads and writes to an array in memory Source:
Question: What is a memory leak? How can we avoid it?

Answer: A memory leak can be avoided by making sure that whatever memory has been dynamically allocated will be cleared after the use of the same. for example

int main()

{ char *myCharData[20];

for (int nLoop =0;nLoop < 20; ++nLoop) { myCharData[nLoop ] = new char[256];





/*Some manipulations here using myCharData*/

/*Now here we have to clear the data. The pla Source:
Question: What is the real-time example for abstract class and pure virtual function?

Answer: Abstract class:

A class that contains at least one pure virtual function is said to be abstract.

For example:

class Base_Employer
// salary(ar-list) is a pure virtual function
virtual void salary(arg-list) = 0;

class derived_Trainee: Public Base_Employer
// salary virtual function is redefined for trainee salary structure

void salay(arg-list)
// redefined for trainee< Source:
Question: Where we use reference and where we use pointers ?Write their differences and advantages and disadvantages .

Answer: values for a 'bool' are 'true' and 'false', whereas for 'BOOL' you can use any 'int' value<br><br>bool - 1 byte<br>BOOL - 4 byte ( 32 bit platform where 'int' = 4 bytes )<br>BOOL - 8 byte ( 64 bit platform where 'int' = 8 bytes ) Source:
Question: Can you store multiple data types in System.Array?

Answer: No. Source:
Question: Can you allocate the memory using malloc() in C and deallocate the same memory using free() in c++

Answer: No, we should not do that. if we do that we can have un-defined or un-predictable results. Which can corrupt other memory too. Instead, we should make a simple rule not to do that. Source:
Question: What is meant by ?method-wars??

Answer: Before 1994 there were different methodologies like Rumbaugh, Booch, Jacobson, Meyer etc who followed their own notations to model the systems. The developers were in a dilemma to choose the method which best accomplishes their needs. This particular span was called as ?method-wars? Source:
Question: Explain "passing by value", "passing by pointer" and "passing by reference"

Answer: There is major defference between these three are when we want to avoid making the copy of variable and we want to change value of actual argument on calling function. there are we use passing by pointer,passing the reference. We can not perform arithmentic operation on reference. Source:
Question: When does a name clash occur?

Answer: A name clash occurs when a name is defined in more than one place. For example., two different class libraries could give two different classes the same name. If you try to use many class libraries at the same time, there is a fair chance that you will be unable to compile or link the program because of name clashes. Source:
Question: What is the difference between realloc() and free()?

Answer: 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 Source:
Question: What happens to the member pointers when an exception occurs in constructor, while allocating memory?How can we over come this ?

Answer: Offcourse it will result memory leak.... so use auto_ptr for such thing .. see following example, i have used two types to avoid memory leaks one is auto_ptr and another is initialize function

#include <iostream>

#include <memory>

class DataClass{


int m_iValue;

DataClass(int i =0):m_iValue(i){}

void show(void) {

std::cout<<std::endl<<"Value :- "<<m_iValue<<std::endl;



clas Source:
Question: Difference between "vector" and "array"?

Answer: Vector and ArrayList are very similar. Both of them represent a 'growable array', where you access to the elements in it through an index.<br>ArrayList it's part of the Java Collection Framework, and has been added with version 1.2, while Vector it's an object that is present since the first version of the JDK. Vector, anyway, has been retrofitted to implement the List interface.<br>The main difference is that Vector it's a synchronized object, while ArrayList it& Source:
Question: Whether unified method and unified modeling language are same or different?

Answer: Unified method is convergence of the Rumbaugh and Booch. Unified modeling lang. is the fusion of Rumbaugh, Booch and Jacobson as well as Betrand Meyer (whose contribution is ?sequence diagram?). Its? the superset of all the methodologies. Source:
Question: Why Pointers are not used in C Language. What are the main differences between C and C++

Answer: Pointer is a strong part of C....................<br><br> there are lot of difference between C , C++.....<br><br> data abstruction, inheritence,polymophisum etc,,,,,,is not facilatted by c.<br><br> Source:
Question: Tell how to check whether a linked list is circular.

Answer: Create two pointers, each set to the start of the list. Update each as follows:

while (pointer1) {
pointer1 = pointer1->next;
pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print ("circular
} Source:
Question: What is friend function and this operator in c++?

Answer: Local class is simply a class thats declared/defined in a function. Yes, it is possible to declare/define a class in a function - and such a class is called local class to that particular funtion. Source:

1 2 3 Next

India News Network
Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
Cache = 0.031006 Seconds