CoolInterview.com - 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
COOLINTERVIEW.COM C++ INTERVIEW QUESTIONS ARRAYS, STRINGS, POINTERS AND REFERENCES IN C++ INTERVIEW QUESTIONS 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
Source: CoolInterview.com
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: CoolInterview.com
Question: What is "strstream??



Answer: Class that reads and writes to an array in memory Source: CoolInterview.com
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: CoolInterview.com
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>
#include<stdio.h>
#include<conio.h>
#include<process.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;
public:
void input();
void withdrawal(int,float);
void deposit(int,float);
void display(int);

};

// Statement o Source: CoolInterview.com
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];

strcpy(myCharData[nLoop],"SABITH");

.......

}

.........................

/*Some manipulations here using myCharData*/

/*Now here we have to clear the data. The pla Source: CoolInterview.com
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: CoolInterview.com
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: CoolInterview.com
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
{
public:
// salary(ar-list) is a pure virtual function
virtual void salary(arg-list) = 0;
};

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

void salay(arg-list)
{
// redefined for trainee< Source: CoolInterview.com
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: CoolInterview.com
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{

public:

int m_iValue;

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

void show(void) {

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

}

};

clas Source: CoolInterview.com
Question: Can you store multiple data types in System.Array?

Answer: No. Source: CoolInterview.com
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: CoolInterview.com
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: CoolInterview.com
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: CoolInterview.com
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: CoolInterview.com
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: CoolInterview.com
Question: How to write programing in c++ language to find a solution to an equation by using stack?

Answer: yes,the solution is possible to use the stack in c++. Source: CoolInterview.com
Question: What problem does the namespace feature solve?

Answer: Multiple providers of libraries might use common global identifiers causing a name collision when an application tries to link with two or more such libraries. The namespace feature surrounds a library?s external declarations with a unique namespace that eliminates the potential for those collisions.
This solution assumes that two library vendors don?t use the same namespace identifier, of course. Source: CoolInterview.com
Question: You have two pairs: new() and delete() and another pair : alloc() and free().
Explain differences between eg. new() and malloc()


Answer: new() allocates continous space for the object instace
malloc() allocates distributed space.
new() is castless, meaning that allocates memory for this specific type,
malloc(), calloc() allocate space for void * that is cated to the specific class type pointer. Source: CoolInterview.com

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.011719 Seconds