- 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: 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: 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: 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 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: Can you store multiple data types in System.Array?

Answer: No. 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: 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:
Question: What is the difference between Mutex and Binary semaphore?

Answer: semaphore is used to synchronize processes. where as mutex is used to provide synchronization between threads running in the same process. 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: What is the difference between an ARRAY and a LIST?

Answer: Array is collection of homogeneous elements.
List is collection of heterogeneous elements.

For Array memory allocated is static and continuous.
For 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. 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: Describe run-time type identification.

Answer: The ability to determine at run time the type of an object by using the typeid operator or the dynamic_cast operator. Source:
Question: STL Containers - What are the types of STL containers?

Answer: There are 3 types of STL containers:

1. Adaptive containers like queue, stack
2. Associative containers like set, map
3. Sequence containers like vector, deque Source:
Question: Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

Answer: Mergesort always makes recursive calls to sort subarrays that are about half size of the original array, resulting in O(n log n) time. Source:
Question: How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

Answer: If you want the code to be even slightly readable, you will use typedefs.
typedef char* (*functiontype_one)(void);
typedef functiontype_one (*functiontype_two)(void);
functiontype_two myarray[N]; //assuming N is a const integral 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: 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 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: How can double dimensional arrays be dynamically initialized in C++?

Answer: example of how to dynamically initialize double dimensional arrays:<br><br>int num[2][3] = {34,32,30,24,22,20};<br><br>num[1][1] = 34<br><br>num[1][2] = 32<br><br>num[1][3] = 30<br><br>num[2][1] = 24<br><br>num[2][2] = 22<br><br>num[2][3] = 20<br> 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.71875 Seconds