C++ QUES

25
C++ OUESTION AND ANSWER What is Dangling Pointer? What is Memory Leak? what is a smart pointer? What is auto pointer? Why should you use smart pointers?. Expla Explain Storage issues of Smart Pointers? Explain whether Member Functions should b class? what is the size of class which has int, What is faster ++i or i++, where i is an what happens if you write this code? str "Hello World"; } cout << foo() << endl; How does free know the size of memory to (int *)malloc(12); followed by free(i); ho call know how much of memory to delete? Write a function to display an integer in

description

candc+

Transcript of C++ QUES

C++ OUESTION AND ANSWER

C++ OUESTION AND ANSWER

What is Dangling Pointer?

What is Memory Leak?

what is a smart pointer?

What is auto pointer?

Why should you use smart pointers?. Explain in detail.

Explain Storage issues of Smart Pointers?

Explain whether Member Functions should be used in Smart Pointer class?

what is the size of class which has int, double, and char?

What is faster ++i or i++, where i is an interger variable?

what happens if you write this code? string& foo() { return "Hello World"; } cout = 0 ( 1, 2, 4, 8, 16, .... ) without using C math library and arithmatic operators ( ie. *, /, +, - and math.h are not allowed)

Write a program to swap two integers without using 3rd integer (ie. Without using any temporary variable)

Write a general swap macro in C : - A macro which can swap any type of data (ie. int, char, float, struct, etc..)

Write a program to delete the entry from the doubly linked list without saving any of the entries of the list to the temporary variable.

What will be the output of this program ? #include main() { int *a, *savea, i; savea = a = (int *) malloc(4 * sizeof(int)); for (i=0; i> foo) syntax work?

Why does my input seem to process past the end of file?

Why is my program ignoring my input request after the first iteration?

Should I end my output lines with std::endl or '\n'?

How can I provide printing for my class Fred?

But shouldn't I always use a printOn() method rather than a friend function?

How can I provide input for my class Fred?

How can I provide printing for an entire hierarchy of classes?

How can I open a stream in binary mode?

How can I "reopen" std::cin and std::cout in binary mode?

How can I write/read objects of my class to/from a data file?

How can I send objects of my class to another computer (e.g., via a socket, TCP/IP, FTP, email, a wireless link, etc.)?

Why can't I open a file in a different directory such as "..\test.dat"?

How can I tell {if a key, which key} was pressed before the user presses the ENTER key?

How can I make it so keys pressed by users are not echoed on the screen?

Does delete p delete the pointer p, or the pointed-to-data *p?

Is it safe to delete the same pointer twice?

Is it safe to delete the same pointer twice?

Can I free() pointers allocated with new? Can I delete pointers allocated with malloc()?

Why should I use new instead of trustworthy old malloc()?

Can I use realloc() on pointers allocated via new?

Do I need to check for NULL after p = new Fred()?

How can I convince my (older) compiler to automatically check new to see if it returns NULL?

Do I need to check for NULL before delete p?

What are the two steps that happen when I say delete p?

In p = new Fred(), does the Fred memory "leak" if the Fred constructor throws an exception?

How do I allocate / unallocate an array of things?

What if I forget the [] when deleteing array allocated via new T[n]?

Can I drop the [] when deleteing array of some built-in type (char, int, etc)?

After p = new Fred[n], how does the compiler know there are n objects to be destructed during delete[] p?

Is it legal (and moral) for a member function to say delete this?

How do I allocate multidimensional arrays using new?

But the previous FAQ's code is SOOOO tricky and error prone! Isn't there a simpler way?

But the above Matrix class is specific to Fred! Isn't there a way to make it generic?

What's another way to build a Matrix template?

Does C++ have arrays whose length can be specified at run-time?

How can I force objects of my class to always be created via new rather than as locals or global/static objects?

How do I do simple reference counting?

How do I provide reference counting with copy-on-write semantics?

How do I provide reference counting with copy-on-write semantics for a hierarchy of classes?

Can you absolutely prevent people from subverting the reference counting mechanism, and if so, should you?

Can I use a garbage collector in C++?

What are the two kinds of garbage collectors for C++?

What are some ways try / catch / throw can improve software quality?

How can I handle a constructor that fails?

How can I handle a destructor that fails?

How should I handle resources if my constructors may throw exceptions?

How do I change the string-length of an array of char to prevent memory leaks even if/when someone throws an exception?

What should I throw?

What should I catch?

But MFC seems to encourage the use of catch-by-pointer; should I do the same?

What does throw; (without an exception object after the throw keyword) mean? Where would I use it?

How do I throw polymorphically?

When I throw this object, how many times will it be copied?

Exception handling seems to make my life more difficult; clearly I'm not the problem, am I??

I have too many try blocks; what can I do about it?

Write a program Sorting With the sort() Algorithm.?

What a derived class inherits or doesn't inherit?

What a derived class can add?

What happens when a derived-class object is created and destroyed?

Design a C++ Class for Playing Cards?

Implement a Complete multiplayer Black Jack Game in C++ using cards and Deck classes previously developed?

Design and Implement a Pointer Based LinkList class using templates?

Write an algorithm to reverse a link list?

Implement a Algorithm to check if the link list is in Ascending order?

Implement a stack class using linked list or pointers?

Implement a queue template class using link list?

Implement a circular link list using pointers?

Implement a Hash Table Abstract data structure using link list?

Find the size of an interger data type with out using sizeof() function?