<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" gd:etag="W/&quot;Ak8CRn44eSp7ImA9WhRRFE4.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890</id><updated>2011-11-27T16:07:47.031-08:00</updated><category term="C++" /><category term="dangling" /><category term="destructor" /><category term="placement new" /><category term="stack unwinding" /><category term="copy constructor" /><category term="C FAQs" /><category term="C++ FAQs" /><category term="MFC" /><category term="stray pointer" /><category term="Memory Alignment" /><category term="Questions" /><category term="Named Constructor Idiom" /><category term="C" /><category term="class" /><category term="Mutable" /><category term="initialization lists" /><category term="assignment" /><category term="VC++" /><category term="Answers" /><category term="bit field" /><category term="Interview" /><category term="constructor" /><category term="name mangling" /><title>VC++ MFC Interview Tips</title><subtitle type="html" /><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/" /><author><name>Jiten</name><uri>http://www.blogger.com/profile/13621053914481467953</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="16" height="16" src="http://img2.blogblog.com/img/b16-rounded.gif" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>17</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/VcMfcInterviewTips" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="vcmfcinterviewtips" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">VcMfcInterviewTips</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><entry gd:etag="W/&quot;AkEHQ3szeSp7ImA9WxVVEkg.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-8603453265781257214</id><published>2009-03-05T05:04:00.000-08:00</published><updated>2009-03-05T05:10:32.581-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-05T05:10:32.581-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Interview" /><category scheme="http://www.blogger.com/atom/ns#" term="Questions" /><category scheme="http://www.blogger.com/atom/ns#" term="Answers" /><category scheme="http://www.blogger.com/atom/ns#" term="C++" /><title>C++ Interview Questions &amp; Answers</title><content type="html">&lt;div style="text-align: justify;"&gt;Q: Is it possible to have Virtual Constructor? If yes, how? If not, Why not possible?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A: There is nothing like Virtual Constructor. The Constructor can’t be virtual as the constructor&lt;/div&gt;&lt;div style="text-align: justify;"&gt;is a code which is responsible for creating an instance of a class and it can’t be delegated to&lt;/div&gt;&lt;div style="text-align: justify;"&gt;any other object by virtual keyword means.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q: What is constructor or ctor?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A: Constructor creates an object and initializes it. It also creates vtable for virtual functions. It is&lt;/div&gt;&lt;div style="text-align: justify;"&gt;different from other methods in a class.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q: What about Virtual Destructor?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A: Yes there is a Virtual Destructor. A destructor can be virtual as it is possible as at runtime&lt;/div&gt;&lt;div style="text-align: justify;"&gt;depending on the type of object caller is calling to, proper destructor will be called.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q: What is the difference between a copy constructor and an overloaded assignment operator?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A: A copy constructor constructs a new object by using the content of the argument object. An&lt;/div&gt;&lt;div style="text-align: justify;"&gt;overloaded assignment operator assigns the contents of an existing object to another existing&lt;/div&gt;&lt;div style="text-align: justify;"&gt;object of the same class.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q: Can a constructor throws an exception? How to handle the error when the constructor fails?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A:The constructor never throws an error.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q: What is default constructor?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A: Constructor with no arguments or all the arguments has default values.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q: What is copy constructor?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A: Constructor which initializes the it's object member variables ( by shallow copying) with another object of the same class. If you don't implement one in your class then compiler implements one for you. for example:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;(a) Boo Obj1(10); // calling Boo constructor&lt;/div&gt;&lt;div style="text-align: justify;"&gt;(b) Boo Obj2(Obj1); // calling boo copy constructor&lt;/div&gt;&lt;div style="text-align: justify;"&gt;(c) Boo Obj2 = Obj1;// calling boo copy constructor&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q: When are copy constructors called?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A: Copy constructors are called in following cases:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;(a) when a function returns an object of that&lt;/div&gt;&lt;div style="text-align: justify;"&gt;class by value&lt;/div&gt;&lt;div style="text-align: justify;"&gt;(b) when the object of that class is passed by&lt;/div&gt;&lt;div style="text-align: justify;"&gt;value as an argument to a function&lt;/div&gt;&lt;div style="text-align: justify;"&gt;(c) when you construct an object based on another&lt;/div&gt;&lt;div style="text-align: justify;"&gt;object of the same class&lt;/div&gt;&lt;div style="text-align: justify;"&gt;(d) When compiler generates a temporary object&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: justify;"&gt;Q: Can a copy constructor accept an object of the same class as parameter, instead of reference&lt;/div&gt;&lt;div style="text-align: justify;"&gt;of the object?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A: No. It is specified in the definition of the copy constructor itself. It should generate an error if&lt;/div&gt;&lt;div style="text-align: justify;"&gt;a programmer specifies a copy constructor with a first argument that is an object and not a&lt;/div&gt;&lt;div style="text-align: justify;"&gt;reference.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q: What is conversion constructor?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A: constructor with a single argument makes that constructor as conversion ctor and it can be&lt;/div&gt;&lt;div style="text-align: justify;"&gt;used for type conversion.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;for example:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;class Boo&lt;/div&gt;&lt;div style="text-align: justify;"&gt;{&lt;/div&gt;&lt;div style="text-align: justify;"&gt;public:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Boo( int i );&lt;/div&gt;&lt;div style="text-align: justify;"&gt;};&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Boo BooObject = 10 ; // assigning int 10 Boo object&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:What is conversion operator??&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A:class can have a public method for specific data type conversions.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;for example:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;class Boo&lt;/div&gt;&lt;div style="text-align: justify;"&gt;{&lt;/div&gt;&lt;div style="text-align: justify;"&gt;double value;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;public:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Boo(int i )&lt;/div&gt;&lt;div style="text-align: justify;"&gt;operator double()&lt;/div&gt;&lt;div style="text-align: justify;"&gt;{&lt;/div&gt;&lt;div style="text-align: justify;"&gt;return value;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;}&lt;/div&gt;&lt;div style="text-align: justify;"&gt;};&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Boo BooObject;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;double i = BooObject; // assigning object to variable i of type double.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;now conversion operator gets called to assign the value.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q: How can I handle a constructor that fails?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A: throw an exception. Constructors don't have a return type, so it's not possible to use return&lt;/div&gt;&lt;div style="text-align: justify;"&gt;codes. The best way to signal constructor failure is therefore to throw an exception.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q: How can I handle a destructor that fails?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;A: Write a message to a log-_le. But do not throw an exception. The C++ rule is that you must&lt;/div&gt;&lt;div style="text-align: justify;"&gt;never throw an exception from a destructor that is being called during the "stack unwinding"&lt;/div&gt;&lt;div style="text-align: justify;"&gt;process of another exception. For example, if someone says throw Foo(), the stack will be&lt;/div&gt;&lt;div style="text-align: justify;"&gt;unwound so all the stack frames between the throw Foo() and the } catch (Foo e) { will get&lt;/div&gt;&lt;div style="text-align: justify;"&gt;popped. This is called stack unwinding. During stack unwinding, all the local objects in all those stack frames are destructed. If one of those destructors throws an exception (say it throws a&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Bar object), the C++ runtime system is in a no-win situation: should it ignore the Bar and end up&lt;/div&gt;&lt;div style="text-align: justify;"&gt;in the } catch (Foo e) { where it was originally headed? Should it ignore the Foo and look for a }&lt;/div&gt;&lt;div style="text-align: justify;"&gt;catch (Bare) { handler? There is no good answer:either choice loses information. So the C++ language guarantees that it will call terminate() at this point, and&lt;/div&gt;&lt;div style="text-align: justify;"&gt;terminate() kills the process. Bang you're dead.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-8603453265781257214?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/uJ3xyFAcQVRdHuEz2aRXrGCIEXE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uJ3xyFAcQVRdHuEz2aRXrGCIEXE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/uJ3xyFAcQVRdHuEz2aRXrGCIEXE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/uJ3xyFAcQVRdHuEz2aRXrGCIEXE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/8603453265781257214/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/03/c-interview-questions-answers.html#comment-form" title="40 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/8603453265781257214?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/8603453265781257214?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/03/c-interview-questions-answers.html" title="C++ Interview Questions &amp; Answers" /><author><name>sandip lakhani</name><uri>http://www.blogger.com/profile/09448206474987605489</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_NjQMfE4WW44/Sak06itZtAI/AAAAAAAAADg/f-Ro7wz-Jko/S220/DSC00305.jpg" /></author><thr:total>40</thr:total></entry><entry gd:etag="W/&quot;AkYCQ3w5cSp7ImA9WxVVEEo.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-4865491518275720595</id><published>2009-03-03T02:56:00.000-08:00</published><updated>2009-03-03T03:02:42.229-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-03T03:02:42.229-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Interview" /><category scheme="http://www.blogger.com/atom/ns#" term="Questions" /><category scheme="http://www.blogger.com/atom/ns#" term="Answers" /><category scheme="http://www.blogger.com/atom/ns#" term="MFC" /><title>Part - 4 MFC Interview Questions &amp; Answers</title><content type="html">&lt;div style="text-align: justify;"&gt;Q:- What is socket?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- A "socket" is an endpoint of communication: an object through which your application communicates with other Windows Sockets applications across a network.The two MFC Windows Sockets programming models are supported by the following classes: CAsyncSocket and CSocket&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is the difference between Synchronous sockets and asynchronous sockets?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- Consider a server application that is listening on a specific port to get data from clients. In synchronous receiving, while the server is waiting to receive data from a client, if the stream is empty the main thread will block until the request for data is satisfied. Hence, the server cannot do anything else until it receives data from the client. If another client attempts to connect to the server at that time, the server cannot process that request because it is blocked on the first client. This behavior is not acceptable for a real-world application where we need to support multiple clients at the same time. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;In asynchronous communication, while the server is listening or receiving data from a client, it can still process connection requests from other clients as well as receive data from those clients. When a server is receiving asynchronously, a separate thread (at the OS level) listens on the socket and will invoke a callback function when a socket event occurs. This callback function in turn will respond and process that socket event.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- Have you ever used win32 APIs ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- MFC is a wrapper around win32 API, It provides classes which uses the win32 API, Some of the API's we usually work with are : GetDlgItemInt,GetDlgItemText,GetWindowTextA,Messag eBoxA,CreateFile,CreateMutex,CreateEvent,WaitForSi ngleObject,CreateWindow,ShowWindow etc.,&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is the difference between ANSI Code and UNICODE ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- ANSI code represents 8bytes data where UNICODE represents 16bytes data for supporting universal languages. One major draw back to ASCII was you could only have 256 different characters. However, languages such as Japanese and Arabic have thousands of characters. Thus ASCII would not work in these situations. The result was Unicode which allowed for up to 65,536 different character&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is the difference between regular dlls and extended dlls?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- Regular dlls wraps only the c/c++ functions. Where extention dlls include c++ interfaces where we can create the objects of it and use in our classes. Extended dlls support object oriented concepts.Regural dlls uses mfc internally and exported functions can be used by any mfc or non-mfc applications.Extention dlls implements reusable classes derived from mfc library,built using dll version of mfc.Only mfc executables(applications/dll-shared version of mfc) can use extention dlls.extention dlls used for passing mfc derived objects b/w applications and dlls. Regulardlls linked both statically and dynamically but extended dlls links dynamically.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is a message map, and what is the advantage of a message map over virtual function ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- MessageMap is a logical table that maps the windows messages to the member functions of the class. We use message maps over virtual function because of lots of overhead. If every windows message had a virtual function associated with it , there would be several hundred bytes per window class of vtable. Message maps means we only pay for the messages we use.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- Given two processes, how can they share memory?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- Processes and thread are very similar but they differ in the way they share their resources. Processes are independent and have its own address space. If two independent processes want to communicate they do this by using the following techniques 1.Message Passing 2.Sockets 3. named pipes&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Or&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Use memory-mapped files to share data memory between processes&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- How to restrict only one instance of a class object to be created?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- Create a Named Mutex.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;HANDLE hMutex=CreateMutex(TRUE,_T(“NamedMutex”))&lt;/div&gt;&lt;div style="text-align: justify;"&gt;And check the Mutex existence for each of your instance launch and dont allow it to launch if it exists.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- How do I dynamically change the mainframe menu?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- CMenu newMenu;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;newMenu.LoadMenu (IDR_MENU1);&lt;/div&gt;&lt;div style="text-align: justify;"&gt;AfxGetMainWnd()-&gt;SetMenu( &amp;amp;newMenu );&lt;/div&gt;&lt;div style="text-align: justify;"&gt;AfxGetMainWnd()-&gt;DrawMenuBar();&lt;/div&gt;&lt;div style="text-align: justify;"&gt;newMenu.Detach ();&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-4865491518275720595?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/og_CAcS8GCdN0bPXwLb1z3STmak/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/og_CAcS8GCdN0bPXwLb1z3STmak/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/og_CAcS8GCdN0bPXwLb1z3STmak/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/og_CAcS8GCdN0bPXwLb1z3STmak/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/4865491518275720595/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/03/part-4-mfc-interview-questions-answers.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/4865491518275720595?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/4865491518275720595?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/03/part-4-mfc-interview-questions-answers.html" title="Part - 4 MFC Interview Questions &amp; Answers" /><author><name>sandip lakhani</name><uri>http://www.blogger.com/profile/09448206474987605489</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_NjQMfE4WW44/Sak06itZtAI/AAAAAAAAADg/f-Ro7wz-Jko/S220/DSC00305.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;A08ASXcyeCp7ImA9WxVWGUU.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-7778653574416753358</id><published>2009-03-02T02:21:00.000-08:00</published><updated>2009-03-02T02:30:48.990-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-02T02:30:48.990-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Interview" /><category scheme="http://www.blogger.com/atom/ns#" term="Questions" /><category scheme="http://www.blogger.com/atom/ns#" term="Answers" /><category scheme="http://www.blogger.com/atom/ns#" term="MFC" /><title>Part - 3 MFC Interview Questions &amp; Answers</title><content type="html">&lt;div style="text-align: justify;"&gt;Q:- What is model and modeless dialog box ? Give some examples?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- When we create Modal Dialog Box we can't move to other windows until this dialog is closed. For eg: MessageBox, where we can't move to the other window until we press ok or cancel. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;When we create Modeless Dilaog Box we can swap to the other windows. For eg: like a conventional window.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- How to create open &amp;amp; save dialogs ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- In CommonDialogs class we have to use CFileDialog class where the first parameter TRUE for open dialog and FALSE for Save dialog.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;For file open:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;CFileDialog SampleDlg(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,"Text Files (*.txt)|*.txt|Comma Separated Values(*.csv)|*.csv||");&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;int iRet = SampleDlg.DoModal();&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is CSingleDocTemplate?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- It’s a document template class used to create single document interface SDI applications. Only one document can be opened at a time. It identifies the document class used to manage the application's data, the frame window class that encloses views of that data, and the view class used to draw visual representations of the data. The document template also stores a resource ID that the framework uses to load menus, accelerators, and other resources that shape the application's user interface.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is the difference between hinstance and hprevinstance in WinMain function?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- hInstance is used for things like loading resources and any other task which is performed on a per-module basis. A module is either the EXE or a DLL loaded into your program. hPrevInstance used to be the handle to the previously run instance of your program (if any) in Win16. It is always NULL for Win32 programs.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- Explain about MDI and CMultiDocTemplate ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- MDI applications are designed using the doc-view architectures in which there could be many views associated with a single document object and an application can open multiple docuements at the same time for eg:WORD.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;In MDI terms, your main window is called the Frame, this is probably the only window you would have in a SDI (Single Document Interface) program. In MDI there is an additional window, called the MDI Client Window which is a child of your Frame window. CMultiDocTemplate is the document template class used to create MDI applications..The document template also stores a resource ID that the framework uses to load menus, accelerators, and other resources that shape the application's user interface.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- Which are the different controls in MFC ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- CAnimateCtrl, CButton, CEdit, CListBox, CComboBox, CRichEditCtrl, CStatic, TreeCtrl, ToolTipCtrl, IPAddressCtrl, TabCtrl,CDa teTimeCtrl, HeaderCtrl, ListCtrl, MonthCalCtrl, OleCtrl, ProgressCtrl, ScrollBar, SliderCtrl, StatusBarCtrl, TollBarCtrl etc.,&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is the use of OnInitDialog ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- This message is sent to the dialog box during the Create, CreateIndirect, or DoModal calls, which occur immediately before the dialog box is displayed. This can be used to intialize the dialog controls or show/hide the controls etc.,&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is the functioning of UpdateData() funciton ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- This is to initialize data in a dialog box, or to retrieve and validate dialog data.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The framework automatically calls UpdateData with bSaveAndValidate set to FALSE when a modal dialog box is created in the default implementation of CDialog::OnInitDialog. The call occurs before the dialog box is visible. The default implementation of CDialog::OnOK calls this member function with bSaveAndValidate set to TRUE to retrieve the data, and if successful, will close the dialog box. If the Cancel button is clicked in the dialog box, the dialog box is closed without the data being retrieved.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- How to update all the views whenever document got updated ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- call UpdateAllViews()- which updates all views associated with the document by calling OnUpdate() function of all the views.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- How to handle RTTI in MFC ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- Run-Time Type Information is a mechanism that allows the type of an object to be determined during the program execution. 3 main elements to RTTI in MFC are&lt;/div&gt;&lt;div style="text-align: justify;"&gt;1. Dynamic_cast operator Used for conversion of polymorphic types.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;2. typeid - used for identifying the exact type of an object &lt;/div&gt;&lt;div style="text-align: justify;"&gt;3. type_info classused to hold the type information returned by typeid.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is serialization ?which function is responsible for serializing data ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- Searialization is the process of streaming the object data to or from a persistent storage medium. It's useful in Doc-View Architecture. CObject :: Serialize() function is used to do serialization.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- what is the use of Mutex and critical section ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- Mutex as the name suggest allows a mutullay exclusive access to a shared resource among the threads. Critical section is a piece of code that can be executed safely to be accessed by two or more threads. Criticalsection provides synchronization means for one process only, while mutexes allow data synchronization across processes. Means two or more threads can share the common resources among more than one &lt;span class="Apple-style-span" style="font-family: 'Trebuchet MS'; font-size: 15px; line-height: 17px; "&gt;application or process boundaries in mutex.&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-7778653574416753358?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/0U2fZ0eKoko8eRUoIhvaHgxZ6Lc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0U2fZ0eKoko8eRUoIhvaHgxZ6Lc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/0U2fZ0eKoko8eRUoIhvaHgxZ6Lc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/0U2fZ0eKoko8eRUoIhvaHgxZ6Lc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/7778653574416753358/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/03/part-3-mfc-interview-questions-answers.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/7778653574416753358?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/7778653574416753358?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/03/part-3-mfc-interview-questions-answers.html" title="Part - 3 MFC Interview Questions &amp; Answers" /><author><name>sandip lakhani</name><uri>http://www.blogger.com/profile/09448206474987605489</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_NjQMfE4WW44/Sak06itZtAI/AAAAAAAAADg/f-Ro7wz-Jko/S220/DSC00305.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DUcGSXs7eCp7ImA9WxVWGE8.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-7591934488873990768</id><published>2009-02-28T05:12:00.000-08:00</published><updated>2009-02-28T05:17:08.500-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-28T05:17:08.500-08:00</app:edited><title>Part - 2 MFC Interview Questions &amp; Answers</title><content type="html">&lt;div style="text-align: justify;"&gt;Q:- What is thread &amp;amp; process?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- Threads are similar to processes, but differ in the way that they share resources. Threads are distinguished from processes in that processes are typically independent, carry considerable state information and have separate address spaces. Threads typically share the memory belonging to their parent process.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- what is the use of AFX_MANAGE_STATE ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- By default, MFC uses the resource handle of the main application to load the resource template. If you have an exported function in a DLL, such as one that launches a dialog box in the DLL, this template is actually stored in the DLL module. You need to switch the module state for the correct handle to be used. You can do this by adding the following code to the beginning of the function:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;AFX_MANAGE_STATE(AfxGetStaticModuleState( ));&lt;/div&gt;&lt;div style="text-align: justify;"&gt;This swaps the current module state with the state returned from AfxGetStaticModuleState until the end of the current scope. If all your resources lies in the single DLL you can even change the default handle to the DLL handle with the help of AfxSetResourceHandle function.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- Why wizards generate enum IDD for dialogs?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- It's good programming practice to do it this way, as from the client code you can always refer to the CMyDlg::IDD without worrying what the actual constant is.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is CArchive class does?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- The CArchive class allows you to save a complex network of objects in a permanent binary form (usually disk storage) that persists after those objects are deleted. Later you can load the objects from persistent storage, reconstituting them in memory. This process of making data persistent is called “serialization.”&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- How to handle command line arguements from simple MFC application ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- m_lpCmdLine Corresponds to the lpCmdLine parameter passed by Windows to WinMain. Points to a null-terminated string that specifies the command line for the application. Use m_lpCmdLine to access any command-line arguments the user entered when the application was started. m_lpCmdLine is a public variable of type LPTSTR.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;BOOL CMyApp::InitInstance()&lt;/div&gt;&lt;div style="text-align: justify;"&gt;{&lt;/div&gt;&lt;div style="text-align: justify;"&gt;// ...&lt;/div&gt;&lt;div style="text-align: justify;"&gt;if (m_lpCmdLine[0] == _T('\0'))&lt;/div&gt;&lt;div style="text-align: justify;"&gt;{&lt;/div&gt;&lt;div style="text-align: justify;"&gt;// Create a new (empty) document.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;OnFileNew();&lt;/div&gt;&lt;div style="text-align: justify;"&gt;}&lt;/div&gt;&lt;div style="text-align: justify;"&gt;else&lt;/div&gt;&lt;div style="text-align: justify;"&gt;{&lt;/div&gt;&lt;div style="text-align: justify;"&gt;// Open a file passed as the first command line parameter.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;OpenDocumentFile(m_lpCmdLine);&lt;/div&gt;&lt;div style="text-align: justify;"&gt;}&lt;/div&gt;&lt;div style="text-align: justify;"&gt;// ...&lt;/div&gt;&lt;div style="text-align: justify;"&gt;}&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is the base class for MFC Framework ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:-CObject&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- If I derive a new class from CObject what are the basic features my derived will get?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:-Searialization, Debugging support, Runtime time class information, compatibility with collection classes.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is the use of CCmdTarget ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- It is the base class for the MFC library message map architecture.Which maps commands/messages to the member functions to handle them. Classes derived from this are CWnd,CWinApp,CFrameWnd,CView, CDocument&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is document-view architecture ? Give me one real time example for SDI ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- Document/view architecture, which defines a program structure that relies on document objects to hold an application's data and on view objects to render views of that data. MFC provides the infrastructure for documents and views in the classes CDocument and CView. example of SDI is a wordpad application&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- Can you explain the relashionship between document,frame and view ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- The frame window is the application's top-level window. It's normally a WS_OVERLAPPEDWINDOW-style window with a resizing border, a title bar, a system menu, and minimize, maximize, and close buttons. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;The view is a child window sized to fit the frame window so that it becomes the frame window's client area. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;The application's data is stored in the document object, a visible representation of which appears in the view. &lt;/div&gt;&lt;div style="text-align: justify;"&gt;For an SDI application, the frame window class is derived from CFrameWnd, the document class is derived from CDocument, and the view class is derived from CView or a related class such as CScrollView.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- How to access document object from view ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- Using GetDocument() function within a CView class.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- What is the entry point for window based applications ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- WinMain() is the entry point for window based applications.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Q:- Explain the flow for a simple win32 based application ?&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans:- Starting point for win32 based applications is WinMain()&lt;/div&gt;&lt;div style="text-align: justify;"&gt;WinMain begins by calling the API function RegisterClass to register a window class. The window class(WNDCLASS) defines important characteristics of a window such as its window procedure address, its default background color, and its icon. Once the WNDCLASS is registered, WinMain calls the all-important CreateWindow function to create the application's window. WinMain follows CreateWindow with calls to ShowWindow and UpdateWindow, which make the window visible and ensure that its WM_PAINT handler is called immediately. Next comes the message loop. In order to retrieve and dispatch messages, WinMain executes a simple while loop that calls the GetMessage, TranslateMessage, and DispatchMessage API functions repeatedly. GetMessage checks the message queue. If a message is available, it is removed from the queue and copied to msg; TranslateMessage converts a keyboard message denoting a character key to an easier-to-use WM_CHAR message, and DispatchMessage dispatches the message to the window procedure. The message loop executes until GetMessage returns 0, which happens only when a WM_QUIT message is retrieved from the message queue. When this occurs, WinMain ends and the program terminates.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-7591934488873990768?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/L3CaB83JjyAUxdpg-jWpQDbpC3g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/L3CaB83JjyAUxdpg-jWpQDbpC3g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/L3CaB83JjyAUxdpg-jWpQDbpC3g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/L3CaB83JjyAUxdpg-jWpQDbpC3g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/7591934488873990768/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/part-2-mfc-interview-questions-answers.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/7591934488873990768?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/7591934488873990768?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/part-2-mfc-interview-questions-answers.html" title="Part - 2 MFC Interview Questions &amp; Answers" /><author><name>sandip lakhani</name><uri>http://www.blogger.com/profile/09448206474987605489</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_NjQMfE4WW44/Sak06itZtAI/AAAAAAAAADg/f-Ro7wz-Jko/S220/DSC00305.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;D0EDQn05cCp7ImA9WxVWGE8.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-2100285833332223537</id><published>2009-02-28T04:53:00.000-08:00</published><updated>2009-02-28T04:54:33.328-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-28T04:54:33.328-08:00</app:edited><title>MFC Interview Questions &amp; Answers</title><content type="html">&lt;div style="text-align: justify;"&gt;Que: What is the difference between GetMessage and PeekMessage ?&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans: GetMessage function waits for a message to be placed in the queue before returning where as PeekMessage function does not wait for a message to be placed in the queue before returning.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Que: What’s the difference between PostMessage and SendMessage?&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans: The PostMessage function places (posts) a message in the message queue associated with the thread that created the specified window and then returns without waiting for the thread to process the message.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Que: How to create a model less dialog?&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans: m_pModeless is a variable of type CDialog or any of its descendants.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;m_pModeless-&gt;Create(IDD_DIALOG1, this);&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;m_pModeless-&gt;ShowWindow(SW_SHOW); &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;this pointer as a paramter suggest we are creating a child dialog of the current dialog/window.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Que: How to setup a timer?&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans: Use the SetTimer function&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;UINT_PTR SetTimer( HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;TIMERPROC lpTimerFunc );&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;To kill the timer use&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;BOOL KillTimer(int nIDEvent);&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Where the nIDEvent is the ID returned by the SetTimer Function.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Que: Name the Synchronization objects ?&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans: Following are the synchronization objects &lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;1) Critical Section 2) Event 3) Mutex 4) Semaphore&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Classes provided for above synchronization objects are:&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;1) CCriticalSection 2) CEvent 3) CMutex 4) CSemaphore&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Que: What Is CMutex ?&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans: An object of class CMutex represents a “mutex” — a synchronization object that allows one thread mutually exclusive access to a resource. Mutexes are useful when only one thread at a time can be allowed to modify data or some other controlled resource. For example, adding nodes to a linked list is a process that should only be allowed by one thread at a time. By using a CMutex object to control the linked list, only one thread at a time can gain access to the list.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;To use a CMutex object, construct the CMutex object when it is needed. Specify the name of the mutex you wish to wait on, and that your application should initially own it. You can then access the mutex when the constructor returns. Call CSyncObject::Unlock when you are done accessing the controlled resource.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;An alternative method for using CMutex objects is to add a variable of type CMutex as a data member to the class you wish to control. During construction of the controlled object, call the constructor of the CMutex data member specifying if the mutex is initially owned, the name of the mutex (if it will be used across process boundaries), and desired security attributes.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;To access resources controlled by CMutex objects in this manner, first create a variable of either type CSingleLock or type CMultiLock in your resource’s access member function. Then call the lock object’s Lock member function (for example, CSingleLock::Lock). At this point, your thread will either gain access to the resource, wait for the resource to be released and gain access, or wait for the resource to be released and time out, failing to gain access to the resource. In any case, your resource has been accessed in a thread-safe manner. To release the resource, use the lock object’s Unlock member function (for example, CSingleLock::Unlock), or allow the lock object to fall out of scope&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Que: What is thread &amp;amp; process?&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans: Threads are similar to processes, but differ in the way that they share resources. Threads are distinguished from processes in that processes are typically independent, carry considerable state information and have separate address spaces. Threads typically share the memory belonging to their parent process.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Que: what is the use of AFX_MANAGE_STATE ?&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Ans: By default, MFC uses the resource handle of the main application to load the resource template. If you have an exported function in a DLL, such as one that launches a dialog box in the DLL, this template is actually stored in the DLL module. You need to switch the module state for the correct handle to be used. You can do this by adding the following code to the beginning of the function:&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;AFX_MANAGE_STATE(AfxGetStaticModuleState( ));&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;This swaps the current module state with the state returned from AfxGetStaticModuleState until the end of the current scope. If all your resources lies in the single DLL you can even change the default handle to the DLL handle with the help of AfxSetResourceHandle function.&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-2100285833332223537?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/A9VcJVt81zlL5j6rvdsHTPH-x1A/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A9VcJVt81zlL5j6rvdsHTPH-x1A/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/A9VcJVt81zlL5j6rvdsHTPH-x1A/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/A9VcJVt81zlL5j6rvdsHTPH-x1A/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/2100285833332223537/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/mfc-interview-questions-answers.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/2100285833332223537?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/2100285833332223537?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/mfc-interview-questions-answers.html" title="MFC Interview Questions &amp; Answers" /><author><name>sandip lakhani</name><uri>http://www.blogger.com/profile/09448206474987605489</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="24" src="http://3.bp.blogspot.com/_NjQMfE4WW44/Sak06itZtAI/AAAAAAAAADg/f-Ro7wz-Jko/S220/DSC00305.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;D0IEQn84eCp7ImA9WxVXFUQ.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-7302374059087097984</id><published>2009-02-13T21:32:00.000-08:00</published><updated>2009-02-13T23:11:43.130-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-13T23:11:43.130-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="C FAQs" /><title>C Inteview Question</title><content type="html">Question :: Read below code and answer the following questions.&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;p class="MsoNormal"&gt;&lt;b style="mso-bidi-font-weight:normal"&gt;&lt;span style="font-size:12.0pt"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" style="border-collapse:collapse;mso-table-layout-alt:fixed;border:none;  mso-border-alt:solid windowtext .5pt;mso-padding-alt:0in 5.4pt 0in 5.4pt;  mso-border-insideh:.5pt solid windowtext;mso-border-insidev:.5pt solid windowtext"&gt;  &lt;tbody&gt;&lt;tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;height:11.15pt"&gt;   &lt;td width="101" valign="top" style="width:75.9pt;border:solid windowtext 1.0pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;LINE&lt;/p&gt;   &lt;/td&gt;   &lt;td width="176" valign="top" style="width:132.25pt;border:solid windowtext 1.0pt;   border-left:none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:   solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;Contains&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:1;height:11.15pt"&gt;   &lt;td width="101" valign="top" style="width:75.9pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;50&lt;/p&gt;   &lt;/td&gt;   &lt;td width="176" valign="top" style="width:132.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;char * b, q, *r;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:2;height:11.15pt"&gt;   &lt;td width="101" valign="top" style="width:75.9pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;200&lt;/p&gt;   &lt;/td&gt;   &lt;td width="176" valign="top" style="width:132.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;b=getbuf();&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:3;height:11.15pt"&gt;   &lt;td width="101" valign="top" style="width:75.9pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;201&lt;/p&gt;   &lt;/td&gt;   &lt;td width="176" valign="top" style="width:132.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;q = *b;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:4;height:11.15pt"&gt;   &lt;td width="101" valign="top" style="width:75.9pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;212&lt;/p&gt;   &lt;/td&gt;   &lt;td width="176" valign="top" style="width:132.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;r= anotherfunction(b);&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:5;height:23.05pt"&gt;   &lt;td width="101" valign="top" style="width:75.9pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt;height:23.05pt"&gt;   &lt;p class="MsoNormal"&gt;213-300&lt;/p&gt;   &lt;/td&gt;   &lt;td width="176" valign="top" style="width:132.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt;height:23.05pt"&gt;   &lt;p class="MsoNormal"&gt;/* we want to use ‘q’ and &lt;span style="mso-spacerun:yes"&gt; &lt;/span&gt;‘r’ here*/&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:6;height:11.15pt"&gt;   &lt;td width="101" valign="top" style="width:75.9pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;2000&lt;/p&gt;   &lt;/td&gt;   &lt;td width="176" valign="top" style="width:132.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;char * getbuf()&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:7;height:11.15pt"&gt;   &lt;td width="101" valign="top" style="width:75.9pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;2001&lt;/p&gt;   &lt;/td&gt;   &lt;td width="176" valign="top" style="width:132.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;{&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:8;height:11.15pt"&gt;   &lt;td width="101" valign="top" style="width:75.9pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;2002&lt;/p&gt;   &lt;/td&gt;   &lt;td width="176" valign="top" style="width:132.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="mso-spacerun:yes"&gt;   &lt;/span&gt;char buff[8];&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:9;height:22.3pt"&gt;   &lt;td width="101" valign="top" style="width:75.9pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt;height:22.3pt"&gt;   &lt;p class="MsoNormal"&gt;2003-2050&lt;/p&gt;   &lt;/td&gt;   &lt;td width="176" valign="top" style="width:132.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt;height:22.3pt"&gt;   &lt;p class="MsoNormal"&gt;/* unspecified, buff defined here *./&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:10;height:14.2pt"&gt;   &lt;td width="101" valign="top" style="width:75.9pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt;height:14.2pt"&gt;   &lt;p class="MsoNormal"&gt;2051&lt;/p&gt;   &lt;/td&gt;   &lt;td width="176" valign="top" style="width:132.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt;height:14.2pt"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="mso-spacerun:yes"&gt;  &lt;/span&gt;return (char *)   buff;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="mso-yfti-irow:11;mso-yfti-lastrow:yes;height:11.15pt"&gt;   &lt;td width="101" valign="top" style="width:75.9pt;border:solid windowtext 1.0pt;   border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;   padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;2052&lt;/p&gt;   &lt;/td&gt;   &lt;td width="176" valign="top" style="width:132.25pt;border-top:none;border-left:   none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;   mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;   mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt;height:11.15pt"&gt;   &lt;p class="MsoNormal"&gt;}&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1. What will be in variable ‘q’ after line 201 is executed?  Under what conditions might this not be so?&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Is there an alternative, but equivalent, way to write line 2000?  If so, what is it?&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3. Is getbuf() a reasonable function? &lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4. Will getbuf() execute at all?&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;5. Please comment on line 2051.&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;6. Is getbuf() good practice, and why?&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;7. What line not given should be provided for compilation?&lt;br /&gt;Answer :&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;(Suggestions and comments are welcome)&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-7302374059087097984?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/kQw54TP0x1090nKHP9PK6notFw0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kQw54TP0x1090nKHP9PK6notFw0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/kQw54TP0x1090nKHP9PK6notFw0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kQw54TP0x1090nKHP9PK6notFw0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/7302374059087097984/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-inteview-question.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/7302374059087097984?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/7302374059087097984?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-inteview-question.html" title="C Inteview Question" /><author><name>Jadav Rakesh</name><uri>http://www.blogger.com/profile/16968103720606178461</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://1.bp.blogspot.com/_bmJLwhFyKLo/SZwGI18HsQI/AAAAAAAAAEg/tUBXOiN50GI/S220/Mr.+Rakesh_1.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CUYCQns8fyp7ImA9WxVWEEg.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-1295085377852123525</id><published>2009-02-11T05:41:00.000-08:00</published><updated>2009-02-19T06:19:23.577-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-19T06:19:23.577-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="C++ FAQs" /><title>Interview FAQs : C++ (Answers End of Post)</title><content type="html">&lt;span style="font-weight: bold;"&gt;1)&lt;/span&gt; Which is the parameter that is added to every non-static member function when it is called?&lt;br /&gt;---------------------------------------------------------------------------------------&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2)&lt;/span&gt;&lt;br /&gt;class base&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;   int bval;&lt;br /&gt;base(){ bval=0;}&lt;br /&gt;};&lt;br /&gt;class deri:public base&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;   int dval;&lt;br /&gt;deri(){ dval=1;}&lt;br /&gt;};&lt;br /&gt;void SomeFunc(base *arr,int size)&lt;br /&gt;{&lt;br /&gt;for(int i=0; i &lt;&gt;bval;&lt;br /&gt;cout &lt;&lt; endl; } int main() { base BaseArr[5]; SomeFunc(BaseArr,5); deri DeriArr[5]; SomeFunc(DeriArr,5); }&lt;br /&gt;---------------------------------------------------------------------------------------&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3) &lt;/span&gt;&lt;br /&gt;class base { public: void baseFun(){ cout &lt;&lt; "from base" &lt;&lt;&gt;baseFun();&lt;br /&gt;}&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;base baseObject;&lt;br /&gt;SomeFunc(&amp;amp;baseObject);&lt;br /&gt;Deri deriObject;&lt;br /&gt;SomeFunc(&amp;amp;deriObject);&lt;br /&gt;}&lt;br /&gt;---------------------------------------------------------------------------------------&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;4)&lt;/span&gt;&lt;br /&gt;class base&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;virtual void baseFun(){ cout &lt;&lt; "from base" &lt;&lt;&gt;baseFun();&lt;br /&gt;}&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;base baseObject;&lt;br /&gt;SomeFunc(&amp;amp;baseObject);&lt;br /&gt;Deri deriObject;&lt;br /&gt;SomeFunc(&amp;amp;deriObject);&lt;br /&gt;}&lt;br /&gt;---------------------------------------------------------------------------------------&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;5)&lt;/span&gt;&lt;br /&gt;class some&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;~some()&lt;br /&gt;{&lt;br /&gt;cout &lt;&lt; "some's destructor" &lt;&lt; endl; } }; void main() { some s; s.~some(); } ---------------------------------------------------------------------------------------&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; 6)&lt;/span&gt; #include class fig2d { int dim1; int dim2; public: fig2d() { dim1=5; dim2=6;} virtual void operator&lt;&lt;(ostream &amp;amp; rhs); }; void fig2d::operator&lt;&lt;(ostream &amp;amp;rhs) { rhs &lt;&lt;&gt;dim1 &lt;&lt;" "&lt;&lt;dim2&gt;&lt;&lt;" "; }  /*class fig3d : public fig2d { int dim3; public: fig3d() { dim3=7;} virtual void operator &lt;&lt; (ostream &amp;amp;rhs); }; void fig3d::operator &lt;&lt; (ostream &amp;amp;rhs) { fig2d::operator &lt;&lt;(rhs); rhs &lt;&lt;&gt;dim3;&lt;br /&gt;}&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;fig2d obj1;&lt;br /&gt;// fig3d obj2;&lt;br /&gt;obj1 &lt;&lt; cout; // obj2 &lt;&lt; cout; }&lt;br /&gt;&lt;/dim2&gt;---------------------------------------------------------------------------------------&lt;br /&gt;&lt;dim2&gt;&lt;span style="font-weight: bold;"&gt; 7) &lt;/span&gt;Class opOverload { Public: bool operator==(opOverload temp); }; bool opOverload::operator==(opOverload temp) { if(*this == temp ) { cout &lt;&lt; "The both are same objects\n"; return true; } else { cout &lt;&lt; "The both are different\n"; return false; } } void main() { opOverload a1, a2; a1= =a2; }&lt;br /&gt;&lt;/dim2&gt;---------------------------------------------------------------------------------------&lt;br /&gt;&lt;dim2&gt;&lt;span style="font-weight: bold;"&gt;8)&lt;/span&gt; Class complex { double re; double im; public: complex() : re(1),im(0.5) {} bool operator==(complex &amp;amp;rhs); operator int(){} }; bool complex::operator == (complex &amp;amp;rhs) { if((this-&gt;re == rhs.re) &amp;amp;&amp;amp; (this-&gt;im == rhs.im))&lt;br /&gt;   return true;&lt;br /&gt;else&lt;br /&gt;   return false;&lt;br /&gt;}&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;complex c1;&lt;br /&gt;cout &lt;&lt;  c1;&lt;br /&gt;}&lt;br /&gt;&lt;/dim2&gt;---------------------------------------------------------------------------------------&lt;br /&gt;&lt;dim2&gt;&lt;span style="font-weight: bold;"&gt;9)&lt;/span&gt;&lt;br /&gt;Class complex&lt;br /&gt;{&lt;br /&gt;double re;&lt;br /&gt;double im;&lt;br /&gt;public:&lt;br /&gt;complex() : re(0),im(0) {}&lt;br /&gt;complex(double n) { re=n,im=n;};&lt;br /&gt;complex(int m,int n) { re=m,im=n;}&lt;br /&gt;void print() { cout &lt;&lt; re; cout &lt;&lt; im;}&lt;br /&gt;};&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;complex c3;&lt;br /&gt;double i=5;&lt;br /&gt;c3 = i;&lt;br /&gt;c3.print();&lt;br /&gt;}&lt;br /&gt;&lt;/dim2&gt;---------------------------------------------------------------------------------------&lt;br /&gt;&lt;dim2&gt;&lt;span style="font-weight: bold;"&gt;C++ Answer&lt;/span&gt;&lt;br /&gt;&lt;/dim2&gt;---------------------------------------------------------------------------------------&lt;br /&gt;&lt;dim2&gt;&lt;span style="font-weight: bold;"&gt;1. &lt;/span&gt;‘this’ pointer&lt;br /&gt;&lt;br /&gt;00000&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2. &lt;/span&gt;01010&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3.&lt;/span&gt; from base&lt;br /&gt;   from base&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;4.&lt;/span&gt; from base&lt;br /&gt;from Derived&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;5.&lt;/span&gt; some's destructor&lt;br /&gt;some's destructor&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;6.&lt;/span&gt; 5 6&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;7. &lt;/span&gt;Runtime Error: Stack Overflow&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;8.&lt;/span&gt; Garbage value&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;9.&lt;/span&gt; 5,5&lt;/dim2&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-1295085377852123525?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/AlhUk3qe82dVs81hNfFN_JSKA78/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AlhUk3qe82dVs81hNfFN_JSKA78/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/AlhUk3qe82dVs81hNfFN_JSKA78/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/AlhUk3qe82dVs81hNfFN_JSKA78/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/1295085377852123525/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/interview-faqs-c_11.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/1295085377852123525?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/1295085377852123525?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/interview-faqs-c_11.html" title="Interview FAQs : C++ (Answers End of Post)" /><author><name>Jadav Rakesh</name><uri>http://www.blogger.com/profile/16968103720606178461</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://1.bp.blogspot.com/_bmJLwhFyKLo/SZwGI18HsQI/AAAAAAAAAEg/tUBXOiN50GI/S220/Mr.+Rakesh_1.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DkYMQXw9fyp7ImA9WxVWEEg.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-1739393814953832796</id><published>2009-02-11T04:53:00.000-08:00</published><updated>2009-02-19T06:36:20.267-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-19T06:36:20.267-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="C FAQs" /><title>Interview FAQs : C   (Answers at end of post)</title><content type="html">&lt;span style="font-weight: bold;"&gt;1.&lt;/span&gt; Base class has some virtual method and derived class has a method with the same name. If we initialize the base class pointer with derived&lt;br /&gt;object, Calling of that virtual method will result in which method being called?&lt;br /&gt;&lt;br /&gt;a. Base method&lt;br /&gt;b. Derived method...&lt;br /&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2.&lt;/span&gt; For the following C program&lt;br /&gt;&lt;br /&gt;#define AREA(x)(3.14*x*x)&lt;br /&gt;main()&lt;br /&gt;{float r1=6.25,r2=2.5,a;&lt;br /&gt;a=AREA(r1);&lt;br /&gt;printf("\n Area of the circle is %f", a);&lt;br /&gt;a=AREA(r2);&lt;br /&gt;printf("\n Area of the circle is %f", a);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What is the output?&lt;br /&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3.&lt;/span&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;int d=5;&lt;br /&gt;printf("%f",d);&lt;br /&gt;}&lt;br /&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;4.&lt;/span&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;int i;&lt;br /&gt;for(i=1;i&lt;4,i++) s="\12345s\n" i="1;" k=" -1"&gt; k=255; */&lt;br /&gt;signed j=-1; /* char k= -1 =&gt; k=65535 */&lt;br /&gt;/* unsigned or signed int k= -1 =&gt;k=65535 */&lt;br /&gt;if(i&lt;j) less="" else="" i=""&gt;j)&lt;br /&gt;printf("greater");&lt;br /&gt;else&lt;br /&gt;if(i==j)&lt;br /&gt;printf("equal");&lt;br /&gt;}&lt;br /&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;span style="font-weight: bold;"&gt;5.&lt;/span&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;char *s="\12345s\n";&lt;br /&gt;printf("%d",sizeof(s));&lt;br /&gt;}&lt;br /&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;span style="font-weight: bold;"&gt;6.&lt;/span&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;unsigned i=1; /* unsigned char k= -1 =&gt; k=255; */&lt;br /&gt;signed j=-1; /* char k= -1 =&gt; k=65535 */&lt;br /&gt;/* unsigned or signed int k= -1 =&gt;k=65535 */&lt;br /&gt;if(i&lt;j) less="" else="" i=""&gt;j)&lt;br /&gt;printf("greater");&lt;br /&gt;else&lt;br /&gt;if(i==j)&lt;br /&gt;printf("equal");&lt;br /&gt;}&lt;br /&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;span style="font-weight: bold;"&gt;7.&lt;/span&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;float j;&lt;br /&gt;j=1000*1000;&lt;br /&gt;printf("%f",j);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;1. 1000000&lt;br /&gt;2. Overflow&lt;br /&gt;3. Error&lt;br /&gt;4. None&lt;br /&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;span style="font-weight: bold;"&gt;8.  &lt;/span&gt;How do you declare an array of N pointers to functions returning&lt;br /&gt; pointers to functions returning pointers to characters?&lt;br /&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;span style="font-weight: bold;"&gt;9.&lt;/span&gt;&lt;br /&gt;int f()&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;f(1);&lt;br /&gt;f(1,2);&lt;br /&gt;f(1,2,3);&lt;br /&gt;}&lt;br /&gt;f(int i,int j,int k)&lt;br /&gt;{&lt;br /&gt;printf("%d %d %d",i,j,k);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;What are the number of syntax errors in the above?&lt;br /&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;span style="font-weight: bold;"&gt;10.&lt;/span&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;int i=7;&lt;br /&gt;printf("%d",i++*i++);&lt;br /&gt;}&lt;br /&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;span style="font-weight: bold;"&gt;11.&lt;/span&gt;&lt;br /&gt;#define one 0&lt;br /&gt;#ifdef one&lt;br /&gt;printf("one is defined ");&lt;br /&gt;#ifndef one&lt;br /&gt;printf("one is not defined ");&lt;br /&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;span style="font-weight: bold;"&gt;12.&lt;/span&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;int count=10,*temp,sum=0;&lt;br /&gt;temp=&amp;count;&lt;br /&gt;*temp=20;&lt;br /&gt;temp=∑&lt;br /&gt;*temp=count;&lt;br /&gt;printf("%d %d %d ",count,*temp,sum);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;span style="font-weight: bold;"&gt;13.&lt;/span&gt; what is alloca()&lt;br /&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;span style="font-weight: bold;"&gt;14.&lt;/span&gt;&lt;br /&gt;main()&lt;br /&gt;{&lt;br /&gt;static i=3;&lt;br /&gt;printf("%d",i--);&lt;br /&gt;return i&gt;0 ? main():0;&lt;br /&gt;}&lt;br /&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;span style="font-weight: bold;"&gt;15.&lt;/span&gt;&lt;br /&gt;char *foo()&lt;br /&gt;{&lt;br /&gt;char result[100]);&lt;br /&gt;strcpy(result,"anything is good");&lt;br /&gt;return(result);&lt;br /&gt;}&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;char *j;&lt;br /&gt;j=foo()&lt;br /&gt;printf("%s",j);&lt;br /&gt;}&lt;br /&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;span style="font-weight: bold;"&gt;16.&lt;/span&gt;&lt;br /&gt;void main()&lt;br /&gt;{&lt;br /&gt;char *s[]={ "dharma","hewlett-packard","siemens","ibm"};&lt;br /&gt;char **p;&lt;br /&gt;p=s;&lt;br /&gt;printf("%s",++*p);&lt;br /&gt;printf("%s",*p++);&lt;br /&gt;printf("%s",++*p);&lt;br /&gt;}&lt;br /&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;span style="font-weight: bold;"&gt;17. &lt;/span&gt;Output of the following program is&lt;br /&gt;main()&lt;br /&gt;{int i=0;&lt;br /&gt;for(i=0;i&lt;20;i++) c="-64;" i="-32" u ="-16;"&gt;i)&lt;br /&gt;{printf("pass1,");&lt;br /&gt;if(c&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;&lt;2,x&gt;&gt;2);&lt;br /&gt;}&lt;br /&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;span style="font-weight: bold;"&gt;18.&lt;/span&gt; What is the ouptut in the following program&lt;br /&gt;main()&lt;br /&gt;{char c=-64;&lt;br /&gt;int i=-32&lt;br /&gt;unsigned int u =-16;&lt;br /&gt;if(c&gt;i)&lt;br /&gt;{printf("pass1,");&lt;br /&gt;if(c&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;&lt;2,x&gt;&gt;2);&lt;br /&gt;}&lt;br /&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;span style="font-weight: bold;"&gt;25.&lt;/span&gt; Find the output for the following C program&lt;br /&gt;&lt;br /&gt;#define swap1(a,b) a=a+b;b=a-b;a=a-b;&lt;br /&gt;main()&lt;br /&gt;{&lt;br /&gt;int x=5,y=10;&lt;br /&gt;swap1(x,y);&lt;br /&gt;printf("%d %d\n",x,y);&lt;br /&gt;swap2(x,y);&lt;br /&gt;printf("%d %d\n",x,y);&lt;br /&gt;}&lt;br /&gt;int swap2(int a,int b)&lt;br /&gt;{&lt;br /&gt;int temp;&lt;br /&gt;temp=a;&lt;br /&gt;b=a;&lt;br /&gt;a=temp;&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;span style="font-weight: bold;"&gt;26. &lt;/span&gt;Find the output for the following C program&lt;br /&gt;main()&lt;br /&gt;{&lt;br /&gt;char *ptr = "Ramco Systems";&lt;br /&gt;(*ptr)++;&lt;br /&gt;printf("%s\n",ptr);&lt;br /&gt;ptr++;&lt;br /&gt;printf("%s\n",ptr);&lt;br /&gt;}&lt;br /&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;span style="font-weight: bold;"&gt;27. &lt;/span&gt;Find the output for the following C program&lt;br /&gt;#include&lt;stdio.h&gt;&lt;br /&gt;main()&lt;br /&gt;{&lt;br /&gt;char *p1;&lt;br /&gt;char *p2;&lt;br /&gt;p1=(char *) malloc(25);&lt;br /&gt;p2=(char *) malloc(25);&lt;br /&gt;strcpy(p1,"Ramco");&lt;br /&gt;strcpy(p2,"Systems");&lt;br /&gt;strcat(p1,p2);&lt;br /&gt;printf("%s",p1);&lt;br /&gt;}&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;28.&lt;/span&gt;  Find the output for the following C program&lt;br /&gt;# define TRUE 0&lt;br /&gt;some code&lt;br /&gt;while(TRUE)&lt;br /&gt;{&lt;br /&gt;some code&lt;br /&gt;}&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;29.&lt;/span&gt; struct list{&lt;br /&gt;   int x;&lt;br /&gt;  struct list *next;&lt;br /&gt;  }*head;&lt;br /&gt;&lt;br /&gt;    the struct head.x =100&lt;br /&gt;&lt;br /&gt;   Is the above assignment to pointer is correct or wrong ?&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;30.&lt;/span&gt;What is the output of the following ?&lt;br /&gt;int i;&lt;br /&gt;  i=1;&lt;br /&gt;  i=i+2*i++;&lt;br /&gt;  printf(%d,i);&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;31. &lt;/span&gt;FILE *fp1,*fp2;&lt;br /&gt;fp1=fopen("one","w")&lt;br /&gt;  fp2=fopen("one","w")&lt;br /&gt;  fputc('A',fp1)&lt;br /&gt;  fputc('B',fp2)&lt;br /&gt;  fclose(fp1)&lt;br /&gt;  fclose(fp2)&lt;br /&gt; }&lt;br /&gt;Find the Error, If Any?&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;32.&lt;/span&gt; #define MAN(x,y) (x)&gt;(y)?(x):(y)&lt;br /&gt;  {int i=10;&lt;br /&gt;  j=5;&lt;br /&gt;  k=0;&lt;br /&gt;  k=MAX(i++,++j);&lt;br /&gt;  printf(%d %d %d %d,i,j,k);&lt;br /&gt;  }&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;33.&lt;/span&gt;void main()&lt;br /&gt;{&lt;br /&gt;int i=7;&lt;br /&gt;printf("%d",i++*i++);&lt;br /&gt;}&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;34.&lt;/span&gt;How will u terminate the statement?&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;35.&lt;/span&gt;select the wrong one&lt;br /&gt;a.a+=1;&lt;br /&gt;b.a*=2;&lt;br /&gt;c.a**=1;&lt;br /&gt;d.a&gt;&gt;=1;&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;36.&lt;/span&gt;pick the odd one&lt;br /&gt;a.malloc&lt;br /&gt;b.calloc&lt;br /&gt;c.new&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;37.&lt;/span&gt;main()&lt;br /&gt;{&lt;br /&gt;char **p=="Hello";&lt;br /&gt;printf("%s",**p);&lt;br /&gt;}&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;38.&lt;/span&gt;main()&lt;br /&gt;{&lt;br /&gt;printf("%d%c\n");&lt;br /&gt;printf("%d%c\n");&lt;br /&gt;}&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;39.&lt;/span&gt;main()&lt;br /&gt;{&lt;br /&gt;int x==5;&lt;br /&gt;printf("%d%d",x++,++x);&lt;br /&gt;}&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;40.&lt;/span&gt;main()&lt;br /&gt;{&lt;br /&gt;int x==4;&lt;br /&gt;printf("%d",printf(" %d %d ",x,x) );&lt;br /&gt;}&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;41.&lt;/span&gt;main()&lt;br /&gt;{&lt;br /&gt;union&lt;br /&gt;{&lt;br /&gt;int i;&lt;br /&gt;char p;&lt;br /&gt;struct&lt;br /&gt;{&lt;br /&gt;int t;&lt;br /&gt;char e;&lt;br /&gt;char o;&lt;br /&gt;};&lt;br /&gt;};&lt;br /&gt;printf("%d\n",sizeof(l) );&lt;br /&gt;}&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;42.&lt;/span&gt;main()&lt;br /&gt;{&lt;br /&gt;int i==0,n==6;&lt;br /&gt;while(n--0);&lt;br /&gt;i+==n;&lt;br /&gt;printf("%d\n",i);&lt;br /&gt;}&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;&lt;span style="font-weight: bold;"&gt;43.&lt;/span&gt;a=3,b=2,c=1;&lt;br /&gt;What's the value of k?&lt;br /&gt;k= a&lt; a="=" a=" 1;" i="=" i="=" a="e" s="'R';" i="=" a1="=" a2="=" t="¡;" a1="¢;" a2=" t;" s1="=" s2="s1;" temp=" s1;" a1= "new" a2= "dictionary" t="¡;" a1="¢;" a2="t;" s1=" s2;" s2=" s1;" temp=" s1;" p="="&gt;add(dharma) &amp;amp;&amp;amp; (*p)-&gt;harma)&lt;br /&gt;"harma" (after printing, p-&gt;add(hewlett-packard) &amp;amp;&amp;amp;(*p)-&gt;harma)&lt;br /&gt;"ewlett-packard"&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;-----------------------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;j) less="" else="" i=""&gt;&lt;j) less="" else="" i=""&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;u) pass2="" fail2="" else="" i=""&gt;&lt;u) pass2="" fail2="" void="" temp="a;" 9="" 15="" swap="" contents="" p="New Sring" a="malloc(strlen(p)" and="" new="" 8="" 5="" 7="" generate="" line="" number="" in="" code="" segment="" value="" unsigned="" else="" maxint="" same="" 1="" not="" maxunit="" what="" will="" be="" result="" static="" return="" g="string" s="" string="" is="" oldstring="" run="" time="" core="" dump="" syntax="" error="" during="" compilation="" none="" of="" these="" p1="Name" char="" p2="(char" y="" find="" output="" for="" the="" following="" c="" program="" int="" d="" n="" x="="&gt;&lt;stdio.h&gt;17.     (d)&lt;br /&gt;&lt;br /&gt;18.     (c)&lt;br /&gt;&lt;br /&gt;19.     (b)&lt;br /&gt;&lt;br /&gt;20.     (a)&lt;br /&gt;&lt;br /&gt;21.     (b)&lt;br /&gt;&lt;br /&gt;22.     An empty string&lt;br /&gt;&lt;br /&gt;23.     57 94&lt;br /&gt;&lt;br /&gt;24.     5 20 1&lt;br /&gt;&lt;br /&gt;25.     10 5&lt;br /&gt;&lt;br /&gt;26.     Samco Systems&lt;br /&gt;&lt;br /&gt;27.     RamcoSystems&lt;br /&gt;&lt;br /&gt;28.    This won't go into the loop as TRUE is defined as 0&lt;br /&gt;&lt;br /&gt;29.     Wrong&lt;br /&gt;&lt;br /&gt;30.     4&lt;br /&gt;&lt;br /&gt;31.    no error. But It will over writes on same file.&lt;br /&gt;&lt;br /&gt;32.    10 5 0&lt;br /&gt;&lt;br /&gt;33.     56&lt;br /&gt;&lt;br /&gt;34.     ;&lt;br /&gt;&lt;br /&gt;35.    C&lt;br /&gt;&lt;br /&gt;36.    C&lt;br /&gt;&lt;br /&gt;37.     Garbage or nothing&lt;br /&gt;&lt;br /&gt;38.     Garbage Value&lt;br /&gt;&lt;br /&gt;39.    6 6&lt;br /&gt;&lt;br /&gt;40.     4 4 5&lt;br /&gt;&lt;br /&gt;41.     4&lt;br /&gt;&lt;br /&gt;42.     -1&lt;br /&gt;&lt;br /&gt;43.     0&lt;br /&gt;&lt;br /&gt;44.     3&lt;br /&gt;&lt;br /&gt;45.     16 21&lt;br /&gt;&lt;br /&gt;46.    UPPER CASE&lt;br /&gt;&lt;br /&gt;47.     5 4 3 2 1&lt;br /&gt;&lt;br /&gt;48.     (newdictionary)-(dictionarynew)&lt;br /&gt;&lt;br /&gt;49.     (newdictionary)-(dictionarynew)&lt;br /&gt;&lt;br /&gt;50.     50&lt;br /&gt;&lt;/stdio.h&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/u)&gt;&lt;/j)&gt;&lt;/j)&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-1739393814953832796?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ctn2TuocXVIGW_c7asYg1RmniXM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ctn2TuocXVIGW_c7asYg1RmniXM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ctn2TuocXVIGW_c7asYg1RmniXM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ctn2TuocXVIGW_c7asYg1RmniXM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/1739393814953832796/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/interview-faqs-c.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/1739393814953832796?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/1739393814953832796?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/interview-faqs-c.html" title="Interview FAQs : C   (Answers at end of post)" /><author><name>Jadav Rakesh</name><uri>http://www.blogger.com/profile/16968103720606178461</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://1.bp.blogspot.com/_bmJLwhFyKLo/SZwGI18HsQI/AAAAAAAAAEg/tUBXOiN50GI/S220/Mr.+Rakesh_1.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CkUDQHc5eyp7ImA9WxVXE0s.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-4143178188315862436</id><published>2009-02-11T03:31:00.000-08:00</published><updated>2009-02-11T05:51:11.923-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-11T05:51:11.923-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="C++" /><title>C++ Interview Questions: Part 9</title><content type="html">&lt;div style="text-align: justify;"&gt;&lt;span style="font-weight: bold;"&gt;31. When can you tell that a memory leak will occur?&lt;/span&gt;&lt;br /&gt;Answer: A memory leak occurs when a program loses the ability to free a block of dynamically allocated memory.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;32.What is a parameterized type?&lt;/span&gt;&lt;br /&gt;Answer: A template is a parameterized construct or type containing generic code that can use or manipulate any type. It is called parameterized because an actual type is a parameter of the code body. Polymorphism may be achieved through parameterized types. This type of polymorphism is called parameteric polymorphism. Parameteric polymorphism is the mechanism by which the same code is used on different types passed as parameters.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;33. Differentiate between a deep copy and a shallow copy?&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;Deep copy involves using the contents of one object to create another instance of the same class. In a deep copy, the two objects may contain ht same information but the target object will have its own buffers and resources. the destruction of either object will not affect the remaining object. The overloaded assignment operator would create a deep copy of objects.&lt;br /&gt;Shallow copy involves copying the contents of one object into another instance of the same class thus creating a mirror image. Owing to straight copying of references and pointers, the two objects will share the same externally contained contents of the other object to be unpredictable.&lt;br /&gt;Explanation:&lt;br /&gt;Using a copy constructor we simply copy the data values member by member. This method of copying is called shallow copy. If the object is a simple class, comprised of built in types and no pointers this would be acceptable. This function would use the values and the objects and its behavior would not be altered with a shallow copy, only the addresses of pointers that are members are copied and not the value the address is pointing to. The data values of the object would then be inadvertently altered by the function. When the function goes out of scope, the copy of the object with all its data is popped off the stack.&lt;br /&gt;If the object has any pointers a deep copy needs to be executed. With the deep copy of an object, memory is allocated for the object in free store and the elements pointed to are copied. A deep copy is used for objects that are returned from a function.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;34. What is an opaque pointer?&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;A pointer is said to be opaque if the definition of the type to which it points to is not included in the current translation unit. A translation unit is the result of merging an implementation file with all its headers and header files.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;35. What is a smart pointer?&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;A smart pointer is an object that acts, looks and feels like a normal pointer but offers more functionality. In C++, smart pointers are implemented as template classes that encapsulate a pointer and override standard pointer operators. They have a number of advantages over regular pointers. They are guaranteed to be initialized as either null pointers or pointers to a heap object. Indirection through a null pointer is checked. No delete is ever necessary. Objects are automatically freed when the last pointer to them has gone away. One significant problem with these smart pointers is that unlike regular pointers, they don't respect inheritance. Smart pointers are unattractive for polymorphic code. Given below is an example for the implementation of smart pointers.&lt;br /&gt;Example:&lt;br /&gt;template &lt;class&gt;&lt;br /&gt;class smart_pointer&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;smart_pointer(); // makes a null pointer&lt;br /&gt;smart_pointer(const X&amp;amp; x) // makes pointer to copy of x&lt;br /&gt;&lt;br /&gt;X&amp;amp; operator *( );&lt;br /&gt;const X&amp;amp; operator*( ) const;&lt;br /&gt;X* operator-&gt;() const;&lt;br /&gt;&lt;br /&gt;smart_pointer(const smart_pointer &lt;x&gt; &amp;amp;);&lt;br /&gt;const smart_pointer &lt;x&gt; &amp;amp; operator =(const smart_pointer&lt;x&gt;&amp;amp;);&lt;br /&gt;~smart_pointer();&lt;br /&gt;private:&lt;br /&gt;//...&lt;br /&gt;};&lt;br /&gt;This class implement a smart pointer to an object of type X. The object itself is located on the heap. Here is how to use it:&lt;br /&gt;smart_pointer &lt;employee&gt; p= employee("Harris",1333);&lt;br /&gt;Like other overloaded operators, p will behave like a regular pointer,&lt;br /&gt;cout&lt;&lt;*p; p-&gt;raise_salary(0.5);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;36. What is reflexive association?&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;The 'is-a' is called a reflexive association because the reflexive association permits classes to bear the is-a association not only with their super-classes but also with themselves. It differs from a 'specializes-from' as 'specializes-from' is usually used to describe the association between a super-class and a sub-class. For example:&lt;br /&gt;Printer is-a printer.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;37. What is slicing?&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;Slicing means that the data added by a subclass are discarded when an object of the subclass is passed or returned by value or from a function expecting a base class object.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Consider the following class declaration:&lt;br /&gt;class base&lt;br /&gt;{&lt;br /&gt;...&lt;br /&gt;base&amp;amp; operator =(const base&amp;amp;);&lt;br /&gt;base (const base&amp;amp;);&lt;br /&gt;}&lt;br /&gt;void fun( )&lt;br /&gt;{&lt;br /&gt;base e=m;&lt;br /&gt;e=m;&lt;br /&gt;}&lt;br /&gt;As base copy functions don't know anything about the derived only the base part of the derived is copied. This is commonly referred to as slicing. One reason to pass objects of classes in a hierarchy is to avoid slicing. Other reasons are to preserve polymorphic behavior and to gain efficiency.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;38. What is name mangling?&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;Name mangling is the process through which your c++ compilers give each function in your program a unique name. In C++, all programs have at-least a few functions with the same name. Name mangling is a concession to the fact that linker always insists on all function names being unique.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Example:&lt;/span&gt;&lt;br /&gt;In general, member names are made unique by concatenating the name of the member with that of the class e.g. given the declaration:&lt;br /&gt;class Bar&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;int ival;&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;ival becomes something like:&lt;br /&gt;// a possible member name mangling&lt;br /&gt;ival__3Bar&lt;br /&gt;Consider this derivation:&lt;br /&gt;class Foo : public Bar&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;int ival;&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;The internal representation of a Foo object is the concatenation of its base and derived class members.&lt;br /&gt;// Pseudo C++ code&lt;br /&gt;// Internal representation of Foo&lt;br /&gt;class Foo&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;int ival__3Bar;&lt;br /&gt;int ival__3Foo;&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;Unambiguous access of either ival members is achieved through name mangling. Member functions, because they can be overloaded, require an extensive mangling to provide each with a unique name. Here the compiler generates the same name for the two overloaded instances(Their argument lists make their instances unique).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;39. What are proxy objects?&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;Objects that points to other objects are called proxy objects or surrogates. Its an object that provides the same interface as its server object but does not have any functionality. During a method invocation, it routes data to the true server object and sends back the return value to the object.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;40. Differentiate between declaration and definition in C++.&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;A declaration introduces a name into the program; a definition provides a unique description of an entity (e.g. type, instance, and function). Declarations can be repeated in a given scope, it introduces a name in a given scope. There must be exactly one definition of every object, function or class used in a C++ program.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;A declaration is a definition unless:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; it declares a function without specifying its body,&lt;br /&gt; it contains an extern specifier and no initializer or function body,&lt;br /&gt; it is the declaration of a static class data member without a class definition,&lt;br /&gt; it is a class name definition,&lt;br /&gt; it is a typedef declaration.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;A definition is a declaration unless:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; it defines a static class data member,&lt;br /&gt; it defines a non-inline member function.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;41. What is cloning?&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;An object can carry out copying in two ways i.e. it can set itself to be a copy of another object, or it can return a copy of itself. The latter process is called cloning.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;42. Describe the main characteristics of static functions.&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt;The main characteristics of static functions include,&lt;br /&gt;&lt;br /&gt; It is without the a this pointer,&lt;br /&gt; It can't directly access the non-static members of its class&lt;br /&gt; It can't be declared const, volatile or virtual.&lt;br /&gt; It doesn't need to be invoked through an object of its class, although for convenience, it may.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;43. Will the inline function be compiled as the inline function always? Justify.&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;An inline function is a request and not a command. Hence it won't be compiled as an inline function always.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Inline-expansion could fail if the inline function contains loops, the address of an inline function is used, or an inline function is called in a complex expression. The rules for inlining are compiler dependent.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;44. Define a way other than using the keyword inline to make a function inline.&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;The function must be defined inside the class.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;45. How can a '::' operator be used as unary operator?&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;The scope operator can be used to refer to members of the global namespace. Because the global namespace doesn’t have a name, the notation :: member-name refers to a member of the global namespace. This can be useful for referring to members of global namespace whose names have been hidden by names declared in nested local scope. Unless we specify to the compiler in which namespace to search for a declaration, the compiler simple searches the current scope, and any scopes in which the current scope is nested, to find the declaration for the name.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;46. What is placement new?&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;When you want to call a constructor directly, you use the placement new. Sometimes you have some raw memory that's already been allocated, and you need to construct an object in the memory you have. Operator new's special version placement new allows you to do it.&lt;br /&gt;class Widget&lt;br /&gt;{&lt;br /&gt;public :&lt;br /&gt;Widget(int widgetsize);&lt;br /&gt;...&lt;br /&gt;Widget* Construct_widget_int_buffer(void *buffer,int widgetsize)&lt;br /&gt;{&lt;br /&gt;return new(buffer) Widget(widgetsize);&lt;br /&gt;}&lt;br /&gt;};&lt;br /&gt;This function returns a pointer to a Widget object that's constructed within the buffer passed to the function. Such a function might be useful for applications using shared memory or memory-mapped I/O, because objects in such applications must be placed at specific addresses or in memory allocated by special routines.&lt;br /&gt;&lt;/employee&gt;&lt;/x&gt;&lt;/x&gt;&lt;/x&gt;&lt;/class&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-4143178188315862436?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/QbFF-8RedppSqnQMNC8YHuvGTmE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QbFF-8RedppSqnQMNC8YHuvGTmE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/QbFF-8RedppSqnQMNC8YHuvGTmE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/QbFF-8RedppSqnQMNC8YHuvGTmE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/4143178188315862436/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions-part-8_11.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/4143178188315862436?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/4143178188315862436?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions-part-8_11.html" title="C++ Interview Questions: Part 9" /><author><name>Jadav Rakesh</name><uri>http://www.blogger.com/profile/16968103720606178461</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://1.bp.blogspot.com/_bmJLwhFyKLo/SZwGI18HsQI/AAAAAAAAAEg/tUBXOiN50GI/S220/Mr.+Rakesh_1.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;C08NRn4_cCp7ImA9WxVXE0g.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-2416763326954131416</id><published>2009-02-11T03:18:00.001-08:00</published><updated>2009-02-11T03:31:37.048-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-11T03:31:37.048-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="C++" /><title>C++ Interview Questions: Part 8</title><content type="html">&lt;span style="font-weight: bold;"&gt;1. What is a modifier?&lt;/span&gt;&lt;br /&gt;Answer: A modifier, also called a modifying function is a member function that changes the value of at least one data member. In other words, an operation that modifies the state of an object. Modifiers are also known as ‘mutators’.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2. What is an accessor?&lt;/span&gt;&lt;br /&gt;Answer: An accessor is a class operation that does not modify the state of an object. The accessor functions need to be declared as const operations&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3. Differentiate between a template class and class template.&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt;Template class: A generic definition or a parameterized class not instantiated until the client provides the needed information. It’s jargon for plain templates.&lt;br /&gt;&lt;br /&gt;Class template: A class template specifies how individual classes can be constructed much like the way a class specifies how individual objects can be constructed. It’s jargon for plain classes.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;4. When does a name clash occur?&lt;/span&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;5. Define namespace.&lt;/span&gt;&lt;br /&gt;Answer: It is a feature in c++ to minimize name collisions in the global name space. This namespace keyword assigns a distinct name to a library that allows other libraries to use the same identifier names without creating any name collisions. Furthermore, the compiler uses the namespace signature for differentiating the definitions.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;6. What is the use of ‘using’ declaration.&lt;/span&gt;&lt;br /&gt;Answer: A using declaration makes it possible to use a name from a namespace without the scope operator.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;7. What is an Iterator class?&lt;/span&gt;&lt;br /&gt;Answer: A class that is used to traverse through the objects maintained by a container class.&lt;br /&gt;&lt;br /&gt;There are five categories of iterators:&lt;br /&gt;&lt;br /&gt; input iterators,&lt;br /&gt; output iterators,&lt;br /&gt; forward iterators,&lt;br /&gt; bidirectional iterators,&lt;br /&gt; random access.&lt;br /&gt;&lt;br /&gt;An iterator is an entity that gives access to the contents of a container object without violating encapsulation constraints. Access to the contents is granted on a one-at-a-time basis in order. The order can be storage order (as in lists and queues) or some arbitrary order (as in array indices) or according to some ordering relation (as in an ordered binary tree). The iterator is a construct, which provides an interface that, when called, yields either the next element in the container, or some value denoting the fact that there are no more elements to examine. Iterators hide the details of access to and update of the elements of a container class.&lt;br /&gt;The simplest and safest iterators are those that permit read-only access to the contents of a container class. The following code fragment shows how an iterator might appear in code:&lt;br /&gt;cont_iter:=new cont_iterator();&lt;br /&gt;x:=cont_iter.next();&lt;br /&gt;while x/=none do&lt;br /&gt;...&lt;br /&gt;s(x);&lt;br /&gt;...&lt;br /&gt;x:=cont_iter.next();&lt;br /&gt;end;&lt;br /&gt;In this example, cont_iter is the name of the iterator. It is created on the first line by instantiation of cont_iterator class, an iterator class defined to iterate over some container class, cont. Succesive elements from the container are carried to x. The loop terminates when x is bound to some empty value. (Here, none)In the middle of the loop, there is s(x) an operation on x, the current element from the container. The next element of the container is obtained at the bottom of the loop.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;9. List out some of the OODBMS available.&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt; GEMSTONE/OPAL of Gemstone systems.&lt;br /&gt; ONTOS of Ontos.&lt;br /&gt; Objectivity of Objectivity inc.&lt;br /&gt; Versant of Versant object technology.&lt;br /&gt; Object store of Object Design.&lt;br /&gt; ARDENT of ARDENT software.&lt;br /&gt; POET of POET software.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;10. List out some of the object-oriented methodologies.&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt; Object Oriented Development (OOD) (Booch 1991,1994).&lt;br /&gt; Object Oriented Analysis and Design (OOA/D) (Coad and Yourdon 1991).&lt;br /&gt; Object Modelling Techniques (OMT) (Rumbaugh 1991).&lt;br /&gt; Object Oriented Software Engineering (Objectory) (Jacobson 1992).&lt;br /&gt; Object Oriented Analysis (OOA) (Shlaer and Mellor 1992).&lt;br /&gt; The Fusion Method (Coleman 1991).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;11. What is an incomplete type?&lt;/span&gt;&lt;br /&gt;Answer: Incomplete types refers to pointers in which there is non availability of the implementation of the referenced location or it points to some location whose value is not available for modification.&lt;br /&gt;Example:&lt;br /&gt;int *i=0x400 // i points to address 400&lt;br /&gt;*i=0; //set the value of memory location pointed by i.&lt;br /&gt;Incomplete types are otherwise called uninitialized pointers.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;12. What is a dangling pointer?&lt;/span&gt;&lt;br /&gt;Answer: A dangling pointer arises when you use the address of an object after its lifetime is over. This may occur in situations like returning addresses of the automatic variables from a function or using the address of the memory block after it is freed.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;13. Differentiate between the message and method.&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt;Message Method&lt;br /&gt;Objects communicate by sending messages Provides response to a message.&lt;br /&gt;to each other.&lt;br /&gt;A message is sent to invoke a method. It is an implementation of an operation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;14. What is an adaptor class or Wrapper class?&lt;/span&gt;&lt;br /&gt;Answer: A class that has no functionality of its own. Its member functions hide the use of a third party software component or an object with the non-compatible interface or a non- object- oriented implementation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;15. What is a Null object?&lt;/span&gt;&lt;br /&gt;Answer: It is an object of some class whose purpose is to indicate that a real object of that class does not exist. One common use for a null object is a return value from a member function that is supposed to return an object with some specified properties but cannot find such an object.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;15. What is a Null object?&lt;/span&gt;&lt;br /&gt;Answer: It is an object of some class whose purpose is to indicate that a real object of that class does not exist. One common use for a null object is a return value from a member function that is supposed to return an object with some specified properties but cannot find such an object.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;16. What is class invariant?&lt;/span&gt;&lt;br /&gt;Answer: A class invariant is a condition that defines all valid states for an object. It is a logical condition to ensure the correct working of a class. Class invariants must hold when an object is created, and they must be preserved under all operations of the class. In particular all class invariants are both preconditions and post-conditions for all operations or member functions of the class.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;17. What do you mean by Stack unwinding?&lt;/span&gt;&lt;br /&gt;Answer: It is a process during exception handling when the destructor is called for all local objects between the place where the exception was thrown and where it is caught.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;18. Define precondition and post-condition to a member function.&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Precondition:&lt;/span&gt; A precondition is a condition that must be true on entry to a member function. A class is used correctly if preconditions are never false. An operation is not responsible for doing anything sensible if its precondition fails to hold.&lt;br /&gt;For example, the interface invariants of stack class say nothing about pushing yet another element on a stack that is already full. We say that isful() is a precondition of the push operation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Post-condition: &lt;/span&gt;A post-condition is a condition that must be true on exit from a member function if the precondition was valid on entry to that function. A class is implemented correctly if post-conditions are never false.&lt;br /&gt;For example, after pushing an element on the stack, we know that isempty() must necessarily hold. This is a post-condition of the push operation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;19. What are the conditions that have to be met for a condition to be an invariant of the class?&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt; The condition should hold at the end of every constructor.&lt;br /&gt; The condition should hold at the end of every mutator(non-const) operation.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;20. What are proxy objects?&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt;Objects that stand for other objects are called proxy objects or surrogates.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;template&lt;br /&gt;class Array2D&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;class Array1D&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;T&amp;amp; operator[] (int index);&lt;br /&gt;const T&amp;amp; operator[] (int index) const;&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;Array1D operator[] (int index);&lt;br /&gt;const Array1D operator[] (int index) const;&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;The following then becomes legal:&lt;br /&gt;Array2Ddata(10,20);&lt;br /&gt;........&lt;br /&gt;cout&lt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;21. Name some pure object oriented languages.&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt; Smalltalk,&lt;br /&gt; Java,&lt;br /&gt; Eiffel,&lt;br /&gt; Sather.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;22. Name the operators that cannot be overloaded.&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;sizeof . .* .-&gt; :: ?:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;23. What is a node class?&lt;/span&gt;&lt;br /&gt;Answer:&lt;br /&gt;&lt;br /&gt;A node class is a class that,&lt;br /&gt; relies on the base class for services and implementation,&lt;br /&gt; provides a wider interface to te users than its base class,&lt;br /&gt; relies primarily on virtual functions in its public interface&lt;br /&gt; depends on all its direct and indirect base class&lt;br /&gt; can be understood only in the context of the base class&lt;br /&gt; can be used as base for further derivation&lt;br /&gt; can be used to create objects.&lt;br /&gt;A node class is a class that has added new services or functionality beyond the services inherited from its base class.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;24. What is an orthogonal base class?&lt;/span&gt;&lt;br /&gt;Answer: If two base classes have no overlapping methods or data they are said to be independent of, or orthogonal to each other. Orthogonal in the sense means that two classes operate in different dimensions and do not interfere with each other in any way. The same derived class may inherit such classes with no difficulty.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;25. What is a container class? What are the types of container classes?&lt;/span&gt;&lt;br /&gt;Answer: A container class is a class that is used to hold objects in memory or external storage. A container class acts as a generic holder. A container class has a predefined behavior and a well-known interface. A container class is a supporting class whose purpose is to hide the topology used for maintaining the list of objects in memory. When a container class contains a group of mixed objects, the container is called a heterogeneous container; when the container is holding a group of objects that are all the same, the container is called a homogeneous container.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;26. What is a protocol class?&lt;/span&gt;&lt;br /&gt;Answer: An abstract class is a protocol class if:&lt;br /&gt;&lt;br /&gt; it neither contains nor inherits from classes that contain member data, non-virtual functions, or private (or protected) members of any kind.&lt;br /&gt; it has a non-inline virtual destructor defined with an empty implementation,&lt;br /&gt; all member functions other than the destructor including inherited functions, are declared pure virtual functions and left undefined.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;27. What is a mixin class?&lt;/span&gt;&lt;br /&gt;Answer: A class that provides some but not all of the implementation for a virtual base class is often called mixin. Derivation done just for the purpose of redefining the virtual functions in the base classes is often called mixin inheritance. Mixin classes typically don't share common bases.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;28. What is a concrete class?&lt;/span&gt;&lt;br /&gt;Answer: A concrete class is used to define a useful object that can be instantiated as an automatic variable on the program stack. The implementation of a concrete class is defined. The concrete class is not intended to be a base class and no attempt to minimize dependency on other classes in the implementation or behavior of the class.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;29.What is the handle class?&lt;/span&gt;&lt;br /&gt;Answer: A handle is a class that maintains a pointer to an object that is programmatically accessible through the public interface of the handle class.&lt;br /&gt;&lt;br /&gt;Explanation:&lt;br /&gt;&lt;br /&gt;In case of abstract classes, unless one manipulates the objects of these classes through pointers and references, the benefits of the virtual functions are lost. User code may become dependent on details of implementation classes because an abstract type cannot be allocated statistically or on the stack without its size being known. Using pointers or references implies that the burden of memory management falls on the user. Another limitation of abstract class object is of fixed size. Classes however are used to represent concepts that require varying amounts of storage to implement them.&lt;br /&gt;&lt;br /&gt;A popular technique for dealing with these issues is to separate what is used as a single object in two parts: a handle providing the user interface and a representation holding all or most of the object's state. The connection between the handle and the representation is typically a pointer in the handle. Often, handles have a bit more data than the simple representation pointer, but not much more. Hence the layout of the handle is typically stable, even when the representation changes and also that handles are small enough to move around relatively freely so that the user needn’t use the pointers and the references.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;30. What is an action class?&lt;/span&gt;&lt;br /&gt;Answer: The simplest and most obvious way to specify an action in C++ is to write a function. However, if the action has to be delayed, has to be transmitted 'elsewhere' before being performed, requires its own data, has to be combined with other actions, etc then it often becomes attractive to provide the action in the form of a class that can execute the desired action and provide other services as well. Manipulators used with iostreams is an obvious example.&lt;br /&gt;&lt;br /&gt;Explanation:&lt;br /&gt;A common form of action class is a simple class containing just one virtual function.&lt;br /&gt;class Action&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt;virtual int do_it( int )=0;&lt;br /&gt;virtual ~Action( );&lt;br /&gt;}&lt;br /&gt;Given this, we can write code say a member that can store actions for later execution without using pointers to functions, without knowing anything about the objects involved, and without even knowing the name of the operation it invokes. For example:&lt;br /&gt;class write_file : public Action&lt;br /&gt;{&lt;br /&gt;File&amp;amp; f;&lt;br /&gt;public:&lt;br /&gt;int do_it(int)&lt;br /&gt;{&lt;br /&gt;return fwrite( ).suceed( );&lt;br /&gt;}&lt;br /&gt;};&lt;br /&gt;class error_message: public Action&lt;br /&gt;{&lt;br /&gt;response_box db(message.cstr( ),"Continue","Cancel","Retry");&lt;br /&gt;switch (db.getresponse( ))&lt;br /&gt;{&lt;br /&gt;case 0: return 0;&lt;br /&gt;case 1: abort();&lt;br /&gt;case 2: current_operation.redo( );return 1;&lt;br /&gt;}&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;A user of the Action class will be completely isolated from any knowledge of derived classes such as write_file and error_message.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-2416763326954131416?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/e6L5U23UdyEDQwowhrZvay-8a8k/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/e6L5U23UdyEDQwowhrZvay-8a8k/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/e6L5U23UdyEDQwowhrZvay-8a8k/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/e6L5U23UdyEDQwowhrZvay-8a8k/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/2416763326954131416/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions-part-8.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/2416763326954131416?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/2416763326954131416?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions-part-8.html" title="C++ Interview Questions: Part 8" /><author><name>Jadav Rakesh</name><uri>http://www.blogger.com/profile/16968103720606178461</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://1.bp.blogspot.com/_bmJLwhFyKLo/SZwGI18HsQI/AAAAAAAAAEg/tUBXOiN50GI/S220/Mr.+Rakesh_1.jpg" /></author><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;CkAMQHw5eCp7ImA9WxVXE0g.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-718546463366606293</id><published>2009-02-11T03:08:00.001-08:00</published><updated>2009-02-11T03:13:01.220-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-11T03:13:01.220-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="C++" /><title>C++ Interview Questions: Part 7</title><content type="html">&lt;div style="text-align: justify;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;Q: What is a default constructor?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: A constructor that has no arguments.&lt;br /&gt;If you don't code one, the compiler provides one if there are no other constructors. If you are going to instantiate an array of objects of the class, the class must have a default constructor.&lt;br /&gt;linkage specification statement turns that feature off during compilation so that the linker properly links function calls to C functions. Another acceptable answer is "I don't know. We never had to do that." Merely describing what a linker does indicates that the programmer does not understand the issue that underlies the question.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Explain the scope resolution operator. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: It permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.&lt;br /&gt;The answer can get complicated. However, it should start with "::". If the programmer is well into the design or use of classes that employ inheritance you might hear a lot about overriding member function overrides to explicitly call a function higher in the hierarchy. That's good to know, but ask specifically about global scope resolution. You're looking for a description of C++'s ability to override the particular C behavior where identifiers in the global scope are always hidden by like identifiers in a local scope.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What are the differences between a C++ struct and C++ class? &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: The default member and base-class access specifiers are different.&lt;br /&gt;This is one of the commonly misunderstood aspects of C++. Believe it or not, many programmers think that a C++ struct is just like a C struct, while a C++ class has inheritance, access specifiers, member functions, overloaded operators, and so on. Some of them have even written books about C++. Actually, the C++ struct has all the features of the class. The only differences are that a struct defaults to public member access and public base-class inheritance, and a class defaults to the private access specifier and private base-class inheritance. Getting this question wrong does not necessarily disqualify an applicant. Getting it right is a definite plus.&lt;br /&gt;Saying, "I don't know" is definitely the wrong answer. I advance an unusual position about this. C++ programmers should at least believe that they know the differences, even when they are wrong about them. Getting it wrong is, therefore, right. You can explain the true difference in the interview and advance the programmer's knowledge. If they disagree vociferously, you have an opportunity to observe how they handle contentious debate when they are wrong and don't know it yet.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: How many ways are there to initialize an int with a constant?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: Two.&lt;br /&gt;There are two formats for initializers in C++ as shown in the example that follows. The first format uses the traditional C notation. The second format uses constructor notation.&lt;br /&gt;int foo = 123;&lt;br /&gt;int bar (123);&lt;br /&gt;It's acceptable when a programmer does not know about the second notation, although they should certainly know about the first one. Many old-timer C programmers who made the switch to C++ never use the second idiom, although some wise heads of C++ profess to prefer it. If your applicant is quick with the right answer, that's a good sign.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: How does throwing and catching exceptions differ from using setjmp and longjmp?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: The throw operation calls the destructors for automatic objects instantiated since entry to the try block.&lt;br /&gt;Exceptions are in the mainstream of C++ now, so most programmers, if they are familiar with setjmp and longjmp, should know the difference. Both idioms return a program from the nested depths of multiple function calls to a defined position higher in the program. The program stack is "unwound" so that the state of the program, with respect to function calls and pushed arguments, is restored as if the calls had not been made. C++ exception handling adds to that behavior the orderly calls to the destructors of automatic objects that were instantiated as the program proceeded from within the try block toward where the throw expression is evaluated.&lt;br /&gt;Applicants might think you want to hear about the notational differences between the two idioms. Let them proceed to explain the syntax of try blocks, catch exception handlers, and throw expressions. Then ask them specifically what happens in a throw that does not happen in a longjmp. Their answer should reflect an understanding of the behavior described in the previous answer.&lt;br /&gt;One valid reason for not knowing about exception handling is that the applicant's experience is exclusively with older C++ compilers that do not implement exception handling. I would prefer that they have at least heard of exception handling, though. Another marginally acceptable reason is that their former supervisors and designers did not mandate and specify the use of exception handling in programs. In that case get the names of those supervisors and designers so that you can decline their applications if they should come a'knocking.&lt;br /&gt;It is not unusual for C and C++ programmers to be unfamiliar with setjmp / longjmp. Those constructs are not particularly intuitive. A C programmer who has written recursive descent parsing algorithms will certainly be familiar with setjmp/longjmp. Others might not, and that's acceptable. In that case, they won't be able to discuss how setjmp/longjmp differs from C++ exception handling, but let the interview turn into a discussion of C++ exception handling in general. That conversation will reveal a lot about a programmer's understanding of C++.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is your reaction to this line of code?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;delete this;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: It's not a good practice.&lt;br /&gt;Many applicants will look at you like you are nuts. They've never heard of this usage, and it's never occurred to them. That's a very good answer. Perhaps they will try to explain the behavior of the statement. Ask them to contemplate its consequences. Two quite acceptable reactions are, "Don't do it," and "Don't do it unless you really know what you are doing and you are a masochist."&lt;br /&gt;A good programmer will insist that you should absolutely never use the statement if the class is to be used by other programmers and instantiated as static, extern, or automatic objects. That much should be obvious.&lt;br /&gt;The code has two built-in pitfalls. First, if it executes in a member function for an extern, static, or automatic object, the program will probably crash as soon as the delete statement executes. There is no portable way for an object to tell that it was instantiated on the heap, so the class cannot assert that its object is properly instantiated. Second, when an object commits suicide this way, the using program might not know about its demise. As far as the instantiating program is concerned, the object remains in scope and continues to exist even though the object did itself in. Subsequent dereferencing of the pointer can and usually does lead to disaster. I think that the language rules should disallow the idiom, but that's another matter.&lt;br /&gt;In More Effective C++ (Addison-Wesley, 1996), Scott Meyers devotes one of his items to "delete this," implying that there are valid applications for the idiom and advancing contrived code kludges to make it seem to work better. A programmer who has read this otherwise very good book might think that the practice is acceptable. Experience leads me to disagree.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is a conversion constructor?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: A constructor that accepts one argument of a different type.&lt;br /&gt;The compiler uses this idiom as one way to infer conversion rules for your class. A constructor with more than one argument and with default argument values can be interpreted by the compiler as a conversion constructor when the compiler is looking for an object of your constructor's type and sees an object of the type of the constructor's first argument.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is the difference between a copy constructor and an overloaded assignment operator?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: A copy constructor constructs a new object by using the content of the argument object. An overloaded assignment operator assigns the contents of an existing object to another existing object of the same class.&lt;br /&gt;First, the applicant must know that a copy constructor is one that has only one argument of the same type as the constructor. The compiler invokes a copy constructor wherever it needs to make a copy of the object, for example to pass an argument by value. If you do not provide a copy constructor, the compiler creates a member- by-member copy constructor for you.&lt;br /&gt;You can write overloaded assignment operators that take arguments of other classes, but that behavior is usually implemented with implicit conversion constructors. If you do not provide an overloaded assignment operator for the class, the compiler creates a default member- by-member assignment operator.&lt;br /&gt;This discussion is a good place to get into why classes need copy constructors and overloaded assignment operators. If the applicant discusses these with respect to data member pointers that point to dynamically allocated resources, the applicant probably has a good grasp of the problem.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: When should you use multiple inheritance?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: There are three acceptable answers: "Never," "Rarely," and "When the problem domain cannot be accurately modeled any other way."&lt;br /&gt;There are some famous C++ pundits and luminaries who disagree with that third answer, but I will accept it.&lt;br /&gt;Let's digress to consider this issue lest your interview turn into a religious debate. Consider an Asset class, Building class, Vehicle class, and CompanyCar class. All company cars are vehicles. Some company cars are assets because the organizations own them. Others might be leased. Not all assets are vehicles. Money accounts are assets. Real estate holdings are assets. Some real estate holdings are buildings. Not all buildings are assets. Ad infinitum. When you diagram these relationships, it becomes apparent that multiple inheritance is a likely and intuitive way to model this common problem domain. The applicant should understand, however, that multiple inheritance, like a chainsaw, is a useful tool that has its perils, needs respect, and is best avoided except when nothing else will do.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is a virtual destructor?&lt;/span&gt;&lt;br /&gt;A: The simple answer is that a virtual destructor is one that is declared with the virtual attribute.&lt;br /&gt;The behavior of a virtual destructor is what is important. If you destroy an object through a pointer or reference to a base class, and the base-class destructor is not virtual, the derived-class destructors are not executed, and the destruction might not be complete.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Explain the ISA and HASA class relationships. How would you implement each in a class design?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: A specialized class "is" a specialization of another class and, therefore, has the ISA relationship with the other class. An Employee ISA Person. This relationship is best implemented with inheritance. Employee is derived from Person. A class may have an instance of another class. For example, an employee "has" a salary, therefore the Employee class has the HASA relationship with the Salary class. This relationship is best implemented by embedding an object of the Salary class in the Employee class.&lt;br /&gt;The answer to this question reveals whether the applicant has an understanding of the fundamentals of object- oriented design, which is important to reliable class design.&lt;br /&gt;There are other relationships. The USESA relationship is when one class uses the services of another. The Employee class uses an object (cout) of the ostream class to display the employee's name on the screen, for example. But if the applicant gets ISA and HASA right, you don't need to go any further.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: When is a template a better solution than a base class?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: When you are designing a generic class to contain or otherwise manage objects of other types, when the format and behavior of those other types are unimportant to their containment or management, and particularly when those other types are unknown (thus, the genericity) to the designer of the container or manager class.&lt;br /&gt;Prior to templates, you had to use inheritance; your design might include a generic List container class and an application-specific Employee class. To put employees in a list, a ListedEmployee class is multiply derived (contrived) from the Employee and List classes. These solutions were unwieldy and error-prone. Templates solved that problem.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is a mutable member?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: One that can be modified by the class even when the object of the class or the member function doing the modification is const.&lt;br /&gt;Understanding this requirement implies an understanding of C++ const, which many programmers do not have. I have seen large class designs that do not employ the const qualifier anywhere. Some of those designs are my own early C++ efforts. One author suggests that some programmers find const to be such a bother that it is easier to ignore const than to try to use it meaningfully. No wonder many programmers don't understand the power and implications of const. Someone who claims to have enough interest in the language and its evolution to keep pace with the ANSI deliberations should not be ignorant of const, however.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is an explicit constructor?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: A conversion constructor declared with the explicit keyword. The compiler does not use an explicit constructor to implement an implied conversion of types. It's purpose is reserved explicitly for construction.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is the Standard Template Library?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: A library of container templates approved by the ANSI committee for inclusion in the standard C++ specification.&lt;br /&gt;A programmer who then launches into a discussion of the generic programming model, iterators, allocators, algorithms, and such, has a higher than average understanding of the new technology that STL brings to C++ programming.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Describe run-time type identification.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: The ability to determine at run time the type of an object by using the typeid operator or the dynamic_cast operator.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What problem does the namespace feature solve?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: 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.&lt;br /&gt;This solution assumes that two library vendors don't use the same namespace identifier, of course.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Are there any new intrinsic (built-in) data types?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: Yes. The ANSI committee added the bool intrinsic type and its true and false value keywords.&lt;br /&gt;Other apparent new types (string, complex, and so on) are implemented as classes in the Standard C++ Library rather than as intrinsic types.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-718546463366606293?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zcrwMrVU6YVHWrZNdheL9Oeg0lk/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zcrwMrVU6YVHWrZNdheL9Oeg0lk/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zcrwMrVU6YVHWrZNdheL9Oeg0lk/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zcrwMrVU6YVHWrZNdheL9Oeg0lk/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/718546463366606293/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions-part-7.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/718546463366606293?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/718546463366606293?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions-part-7.html" title="C++ Interview Questions: Part 7" /><author><name>Jadav Rakesh</name><uri>http://www.blogger.com/profile/16968103720606178461</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://1.bp.blogspot.com/_bmJLwhFyKLo/SZwGI18HsQI/AAAAAAAAAEg/tUBXOiN50GI/S220/Mr.+Rakesh_1.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CkEMRn4_eyp7ImA9WxVQGU4.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-3446459502127152337</id><published>2009-02-06T06:24:00.000-08:00</published><updated>2009-02-06T06:31:27.043-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-06T06:31:27.043-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="dangling" /><category scheme="http://www.blogger.com/atom/ns#" term="C" /><category scheme="http://www.blogger.com/atom/ns#" term="stack unwinding" /><category scheme="http://www.blogger.com/atom/ns#" term="Interview" /><category scheme="http://www.blogger.com/atom/ns#" term="Questions" /><category scheme="http://www.blogger.com/atom/ns#" term="stray pointer" /><category scheme="http://www.blogger.com/atom/ns#" term="bit field" /><category scheme="http://www.blogger.com/atom/ns#" term="Memory Alignment" /><category scheme="http://www.blogger.com/atom/ns#" term="C++" /><category scheme="http://www.blogger.com/atom/ns#" term="name mangling" /><category scheme="http://www.blogger.com/atom/ns#" term="Mutable" /><title>C Interview Questions : Part 6</title><content type="html">&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;C Questions:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q:What is Mutable?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans:&lt;/span&gt; this keyword can only be applied to non-static and non-const data members of a class. If a data member is declared mutable, then it is legal to assign a value to this data member from a const member function.&lt;br /&gt;Mutable member-variable-declaration;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q:What is c++ bit field?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans:&lt;/span&gt; Classes and structures can contain members that occupy less storage than an integral type. These members are specified as bit fields. The syntax for bit-field member-declarator specification follows:&lt;br /&gt;&lt;br /&gt;Declarator: constant-expression&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;What is Memory Alignment?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans:&lt;/span&gt; Most CPUs require that objects and variables reside at particular offsets in the system's memory. For example, 32-bit processors require a 4-byte integer to reside at a memory address that is evenly divisible by 4. This requirement is called "memory alignment". Thus, a 4-byte int can be located at memory address 0x2000 or 0x2004, but not at 0x2001.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; Q:What is dangling pointer?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans:&lt;/span&gt; Pointers that do not point to a valid object of the appropriate type. Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q:What is in Name mangling?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans:&lt;/span&gt; Name mangling, (the more politically correct term is name-decoration, although it is rarely used) is a method used by a C++ compiler to generate unique names for identifiers in a program. The exact details of the algorithm are compiler-dependent, and they may vary from one version to another.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q:What stack unwinding?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ans:&lt;/span&gt; When an exception is thrown and control passes from a try block to a handler, the C++ run time calls destructors for all automatic objects constructed since the beginning of the try block. This process is called stack unwinding. The automatic objects are destroyed in reverse order of their construction.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-3446459502127152337?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/cpA837l3uYRxGUTPNWoZOVMkD4k/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cpA837l3uYRxGUTPNWoZOVMkD4k/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/cpA837l3uYRxGUTPNWoZOVMkD4k/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/cpA837l3uYRxGUTPNWoZOVMkD4k/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/3446459502127152337/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions-part-6.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/3446459502127152337?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/3446459502127152337?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions-part-6.html" title="C Interview Questions : Part 6" /><author><name>Jadav Rakesh</name><uri>http://www.blogger.com/profile/16968103720606178461</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://1.bp.blogspot.com/_bmJLwhFyKLo/SZwGI18HsQI/AAAAAAAAAEg/tUBXOiN50GI/S220/Mr.+Rakesh_1.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DU8MRHk6fSp7ImA9WxVQGU0.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-2784468610450000001</id><published>2009-02-05T21:57:00.001-08:00</published><updated>2009-02-06T00:11:25.715-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-06T00:11:25.715-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="constructor" /><category scheme="http://www.blogger.com/atom/ns#" term="Interview" /><category scheme="http://www.blogger.com/atom/ns#" term="Questions" /><category scheme="http://www.blogger.com/atom/ns#" term="copy constructor" /><category scheme="http://www.blogger.com/atom/ns#" term="C++" /><category scheme="http://www.blogger.com/atom/ns#" term="destructor" /><title>Constructors And Destructors</title><content type="html">&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Constructors:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;*What is the use of Constructor&lt;/span&gt;?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer ::&lt;/span&gt; The main use of constructors is to initialize objects. The function of initialization is automatically carried out by the use of a special member function called a constructor.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;*General Syntax of Constructor&lt;/span&gt;&lt;br /&gt;Constructor is a special member function that takes the same name as the class name. The syntax generally is as given below:&lt;br /&gt;&lt;br /&gt;&lt;class&gt; { arguments};&lt;br /&gt;The default constructor for a class X has the form&lt;br /&gt;X::X()&lt;br /&gt;In the above example the arguments is optional.&lt;br /&gt;&lt;br /&gt;The constructor is automatically named when an object is created. A constructor is named whenever an object is defined or dynamically allocated using the "new" operator.&lt;br /&gt;&lt;br /&gt;There are several forms in which a constructor can take its shape namely:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;*Default Constructor: &lt;/span&gt;&lt;br /&gt;This constructor has no arguments in it.  Default Constructor is also called as no argument constructor.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;class XYZ&lt;br /&gt;{&lt;br /&gt;  private:&lt;br /&gt;      int a,b;&lt;br /&gt;  public:&lt;br /&gt;     XYZ ();&lt;br /&gt;      ...&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;XYZ:: XYZ ()&lt;br /&gt;{&lt;br /&gt;  a=0;&lt;br /&gt;  b=0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;*Copy constructor: &lt;/span&gt;&lt;br /&gt;This constructor takes one argument. Also called one argument constructor. The main use of copy constructor is to initialize the objects while in creation, also used to copy an object. The copy constructor allows the programmer to create a new object from an existing one by initialization.&lt;br /&gt;&lt;br /&gt;For example to invoke a copy constructor the programmer writes:&lt;br /&gt;XYZ e3(e2);&lt;br /&gt;or&lt;br /&gt;XYZ e3=e2;&lt;br /&gt;Both the above formats can be sued to invoke a copy constructor.&lt;br /&gt;&lt;br /&gt;For Example:&lt;br /&gt;#include &lt;iostream.h&gt;&lt;br /&gt;class XYZ()&lt;br /&gt;{&lt;br /&gt;  private:&lt;br /&gt;      int a;&lt;br /&gt;  public:&lt;br /&gt;      XYZ()&lt;br /&gt;      { }&lt;br /&gt;      XYZ(int w)&lt;br /&gt;  {&lt;br /&gt;      a=w;&lt;br /&gt;  }&lt;br /&gt;  XYZ(XYZ&amp;amp; e)&lt;br /&gt;  {&lt;br /&gt;      a=e.a;&lt;br /&gt;      cout&lt;&lt;” Example of Copy Constructor”;     }     void result()     {         cout&lt;&lt; ne3="”;e3.result();" e3="50" style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Destructors:&lt;/span&gt;&lt;br /&gt;&lt;/iostream.h&gt;&lt;/class&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;*What is the use of Destructors?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Answer::&lt;/span&gt; Destructors are also special member functions used in C++ programming language. Destructors have the opposite function of a constructor. The main use of destructors is to release dynamic allocated memory. Destructors are used to free memory, release resources and to perform other clean up. Destructors are automatically named when an object is destroyed. Like constructors, destructors also take the same name as that of the class name.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;*General Syntax of Destructors&lt;/span&gt;&lt;br /&gt;~ classname();&lt;br /&gt;The above is the general syntax of a destructor. In the above, the symbol tilda ~ represents a destructor which precedes the name of the class.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-2784468610450000001?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/9mUC0oSDgjFubQWntxthG3s7Kag/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9mUC0oSDgjFubQWntxthG3s7Kag/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/9mUC0oSDgjFubQWntxthG3s7Kag/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/9mUC0oSDgjFubQWntxthG3s7Kag/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/2784468610450000001/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/constructors-and-destructors.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/2784468610450000001?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/2784468610450000001?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/constructors-and-destructors.html" title="Constructors And Destructors" /><author><name>Jadav Rakesh</name><uri>http://www.blogger.com/profile/16968103720606178461</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://1.bp.blogspot.com/_bmJLwhFyKLo/SZwGI18HsQI/AAAAAAAAAEg/tUBXOiN50GI/S220/Mr.+Rakesh_1.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;A0IGRXgyfyp7ImA9WxVQGEQ.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-1758338223764259947</id><published>2009-02-05T21:35:00.000-08:00</published><updated>2009-02-05T21:52:04.697-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-05T21:52:04.697-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="constructor" /><category scheme="http://www.blogger.com/atom/ns#" term="C" /><category scheme="http://www.blogger.com/atom/ns#" term="Interview" /><category scheme="http://www.blogger.com/atom/ns#" term="class" /><category scheme="http://www.blogger.com/atom/ns#" term="Questions" /><category scheme="http://www.blogger.com/atom/ns#" term="Named Constructor Idiom" /><category scheme="http://www.blogger.com/atom/ns#" term="initialization lists" /><category scheme="http://www.blogger.com/atom/ns#" term="C++" /><category scheme="http://www.blogger.com/atom/ns#" term="VC++" /><category scheme="http://www.blogger.com/atom/ns#" term="assignment" /><title>C++ Interview Questions: Part 4</title><content type="html">&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Part 4&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-weight: bold;"&gt;Q: Should my constructors use "initialization lists" or "assignment"?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;A&lt;/span&gt;: Initialization lists. In fact, constructors should initialize as a rule all member objects in the initialization list. One exception is discussed further down. Consider the following constructor that initializes member object x_ using an initialization list:&lt;br /&gt;&lt;br /&gt;Fred::Fred() : x_(whatever) { }.&lt;br /&gt;&lt;br /&gt;The most common benefit of doing this is improved performance. For example, if the expression whatever is the same type as member variable x_, the result of the whatever expression is constructed directly inside x_ the compiler does not make a separate copy of the object.&lt;br /&gt;&lt;br /&gt;Even if the types are not the same, the compiler is usually able to do a better job with initialization lists than with assignments. The other (inefficient) way to build constructors is via assignment, such as: Fred::Fred() { x_ = whatever; }. In this case the expression whatever causes a separate, temporary object to be created, and this temporary object is passed into the x_ object's assignment operator. Then that temporary object is destructed at the point. That's inefficient.&lt;br /&gt;&lt;br /&gt;As if that wasn't bad enough, there's another source of inefficiency when using assignment in a constructor: the member object will get fully constructed by its default constructor, and this might, for example, allocate some default amount of memory or open some default file.&lt;br /&gt;&lt;br /&gt;All this work could be for naught if the whatever expression and/or assignment operator causes the object to close that file and/or release that memory (e.g., if the default constructor didn't allocate a large enough pool of memory or if it opened the wrong file). &lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;br /&gt;Conclusion&lt;/span&gt;: All other things being equal, your code will run faster if you use initialization lists rather than assignment. Note: There is no performance difference if the type of x_ is some built-in/intrinsic type, such as int or char* or float.&lt;br /&gt;&lt;br /&gt;But even in these cases, my personal preference is to set those data members in the initialization list rather than via assignment for consistency.&lt;br /&gt;&lt;br /&gt;Another symmetry argument in favor of using initialization lists even for built-in/intrinsic types: non-static const and nonstatic reference data members can't be assigned a value in the constructor, so for symmetry it makes sense to initialize everything in the initialization list. Now for the exceptions. Every rule has exceptions (hmmm; does "every rule has exceptions" have exceptions? reminds me of Gdel's Incompleteness Theorems), and there are a couple of exceptions to the "use initialization lists" rule.&lt;br /&gt;&lt;br /&gt;Bottom line is to use common sense: if it's cheaper, better, faster, etc. to not use them, then by all means, don't use them. This might happen when your class has two constructors that need to initialize the this object's data members in different orders. Or it might happen when two data members are self-referential. Or when a datamember needs a reference to the this object, and you want to avoid a compiler warning about using the this keyword prior to the { that begins the constructor's body (when your particular compiler happens to issue that particular warning). Or when you need to do an if/throw test on a variable (parameter, global, etc.) prior to using that variable to initialize one of your this members. This list is not exhaustive; please don't write me asking me to add another "Or when...". The point is simply this: use common sense.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Should you use the this pointer in the constructor?&lt;/span&gt;&lt;br /&gt;A: Some people feel you should not use the this pointer in a constructor because the object is not fully formed yet.&lt;br /&gt;&lt;br /&gt;However you can use this in the constructor (in the {body} and even in the initialization list) if you are careful.&lt;br /&gt;&lt;br /&gt;Here is something that always works: the {body} of a constructor (or a function called from the constructor) can reliably access the data members declared in a base class and/or the data members declared in the constructor's own class.&lt;br /&gt;&lt;br /&gt;This is because all those data members are guaranteed to have been fully constructed by the time the constructor's {body} starts executing.&lt;br /&gt;&lt;br /&gt;Here is something that never works: the {body} of a constructor (or a function called from the constructor) cannot get down to a derived class by calling a virtual member function that is overridden in the derived class.&lt;br /&gt;&lt;br /&gt;If your goal was to get to the overridden function in the derived class, you won't get what you want. Note that you won't get to the override in the derived class independent of how you call the virtual member function: explicitly using the this pointer (e.g., this-&gt;method()), implicitly using the this pointer (e.g., method()), or even calling some other function that calls the virtual member function on your this object.&lt;br /&gt;&lt;br /&gt;The bottom line is this: even if the caller is constructing an object of a derived class, during the constructor of the base class, your object is not yet of that derived class. You have been warned. Here is something that sometimes works: if you pass any of the data members in this object to another data member's initializer, you must make sure that the other data member has already been initialized.&lt;br /&gt;&lt;br /&gt;The good news is that you can determine whether the other data member has (or has not) been initialized using some straightforward language rules that are independent of the particular compiler you're using. The bad news it that you have to know those language rules (e.g., base class sub-objects are initialized first (look up the order if you have multiple and/or virtual inheritance!), then data members defined in the class are initialized in the order in which they appear in the class declaration).&lt;br /&gt;&lt;br /&gt;If you don't know these rules, then don't pass any data member from the this object (regardless of whether or not you explicitly use the this keyword) to any other data member's initializer! And if you do know the rules, please be careful.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is the "Named Constructor Idiom"?&lt;/span&gt;&lt;br /&gt;A: A technique that provides more intuitive and/or safer construction operations for users of your class. The problem is that constructors always have the same name as the class.&lt;br /&gt;&lt;br /&gt;Therefore the only way to differentiate between the various constructors of a class is by the parameter list. But if there are lots of constructors, the differences between them become somewhat subtle and error prone. With the Named Constructor Idiom, you declare all the class's constructors in the private or protected sections, and you provide public static methods that return an object. These static methods are the so-called "Named Constructors."&lt;br /&gt;&lt;br /&gt;In general there is one such static method for each different way to construct an object. For example, suppose we are building a Point class that represents a position on the X-Y plane. Turns out there are two common ways to specify a 2-space coordinate: rectangular coordinates (X+Y), polar coordinates (Radius+Angle). (Don't worry if you can't remember these; the point isn't the particulars of coordinate systems; the point is that there are several ways to create a Point object.) Unfortunately the parameters for these two coordinate systems are the same: two floats. This would create an ambiguity error in the overloaded constructors:&lt;br /&gt;&lt;br /&gt;class Point {&lt;br /&gt;public:&lt;br /&gt;Point(float x, float y); // Rectangular coordinates&lt;br /&gt;Point(float r, float a); // Polar coordinates (radius and angle)&lt;br /&gt;// ERROR: Overload is Ambiguous: Point::Point(float,float)&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;Point p = Point(5.7, 1.2); // Ambiguous: Which coordinate system?&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;One way to solve this ambiguity is to use the Named Constructor Idiom:&lt;br /&gt;#include // To get sin() and cos()&lt;br /&gt;class Point {&lt;br /&gt;public:&lt;br /&gt;static Point rectangular(float x, float y); // Rectangular coord's&lt;br /&gt;static Point polar(float radius, float angle); // Polar coordinates&lt;br /&gt;// These static methods are the so-called "named constructors"&lt;br /&gt;...&lt;br /&gt;private:&lt;br /&gt;Point(float x, float y); // Rectangular coordinates&lt;br /&gt;float x_, y_;&lt;br /&gt;};&lt;br /&gt;inline Point::Point(float x, float y)&lt;br /&gt;: x_(x), y_(y) { }&lt;br /&gt;inline Point Point::rectangular(float x, float y)&lt;br /&gt;{ return Point(x, y); }&lt;br /&gt;inline Point Point::polar(float radius, float angle)&lt;br /&gt;{ return Point(radius*cos(angle), radius*sin(angle)); }&lt;br /&gt;Now the users of Point have a clear and unambiguous syntax for creating Points in either&lt;br /&gt;coordinate system:&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;Point p1 = Point::rectangular(5.7, 1.2); // Obviously rectangular&lt;br /&gt;Point p2 = Point::polar(5.7, 1.2); // Obviously polar&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Make sure your constructors are in the protected section if you expect Point to have derived classes. The Named Constructor Idiom can also be used to make sure your objects are always created via new. Note that the Named Constructor Idiom, at least as implemented above, is just as fast as directly calling a constructor modern compilers will not make any extra copies of your object.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-1758338223764259947?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/i4brvTVIhIojliYHynHHihYbg4o/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/i4brvTVIhIojliYHynHHihYbg4o/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/i4brvTVIhIojliYHynHHihYbg4o/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/i4brvTVIhIojliYHynHHihYbg4o/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/1758338223764259947/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions_2719.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/1758338223764259947?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/1758338223764259947?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions_2719.html" title="C++ Interview Questions: Part 4" /><author><name>Jadav Rakesh</name><uri>http://www.blogger.com/profile/16968103720606178461</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://1.bp.blogspot.com/_bmJLwhFyKLo/SZwGI18HsQI/AAAAAAAAAEg/tUBXOiN50GI/S220/Mr.+Rakesh_1.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;A0MDSHY-eCp7ImA9WxVQGEQ.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-8907623187367084036</id><published>2009-02-05T21:27:00.000-08:00</published><updated>2009-02-05T21:51:19.850-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-05T21:51:19.850-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="constructor" /><category scheme="http://www.blogger.com/atom/ns#" term="C" /><category scheme="http://www.blogger.com/atom/ns#" term="Interview" /><category scheme="http://www.blogger.com/atom/ns#" term="class" /><category scheme="http://www.blogger.com/atom/ns#" term="placement new" /><category scheme="http://www.blogger.com/atom/ns#" term="Questions" /><category scheme="http://www.blogger.com/atom/ns#" term="Answers" /><category scheme="http://www.blogger.com/atom/ns#" term="copy constructor" /><category scheme="http://www.blogger.com/atom/ns#" term="C++" /><category scheme="http://www.blogger.com/atom/ns#" term="destructor" /><category scheme="http://www.blogger.com/atom/ns#" term="VC++" /><title>C++ Interview Questions: Part 3</title><content type="html">&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Part 3&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-weight: bold;"&gt;Q: When I write a destructor, do I need to explicitly call the destructors for my member objects?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;A&lt;/span&gt;: No. You never need to explicitly call a destructor (except with placement new).&lt;br /&gt;A class's destructor (whether or not you explicitly define one) automagically invokes the&lt;br /&gt;destructors for member objects. They are destroyed in the reverse order they appear within the declaration for the class.&lt;br /&gt;&lt;br /&gt;class Member {&lt;br /&gt;public:&lt;br /&gt;~Member();&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;class Fred {&lt;br /&gt;public:&lt;br /&gt;~Fred();&lt;br /&gt;...&lt;br /&gt;private:&lt;br /&gt;Member x_;&lt;br /&gt;Member y_;&lt;br /&gt;Member z_;&lt;br /&gt;};&lt;br /&gt;Fred::~Fred()&lt;br /&gt;{&lt;br /&gt;// Compiler automagically calls z_.~Member()&lt;br /&gt;// Compiler automagically calls y_.~Member()&lt;br /&gt;// Compiler automagically calls x_.~Member()&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: When I write a derived class's destructor, do I need to explicitly call the destructor for my base class?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;A&lt;/span&gt;: No. You never need to explicitly call a destructor (except with placement new).&lt;br /&gt;A derived class's destructor (whether or not you explicitly define one) automagically invokes the destructors for base class subobjects. Base classes are destructed after member objects. In the event of multiple inheritance, direct base classes are destructed in the reverse order of their appearance in the inheritance list.&lt;br /&gt;&lt;br /&gt;class Member {&lt;br /&gt;public:&lt;br /&gt;~Member();&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;class Base {&lt;br /&gt;public:&lt;br /&gt;virtual ~Base(); // A virtual destructor&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;class Derived : public Base {&lt;br /&gt;public:&lt;br /&gt;~Derived();&lt;br /&gt;...&lt;br /&gt;private:&lt;br /&gt;Member x_;&lt;br /&gt;};&lt;br /&gt;Derived::~Derived()&lt;br /&gt;{&lt;br /&gt;// Compiler automagically calls x_.~Member()&lt;br /&gt;// Compiler automagically calls Base::~Base()&lt;br /&gt;}&lt;br /&gt;Note: Order dependencies with virtual inheritance are trickier. If you are relying on order&lt;br /&gt;dependencies in a virtual inheritance hierarchy, you'll need a lot more information than is in this FAQ.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Is there any difference between List x; and List x();?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;A&lt;/span&gt;: A big difference! Suppose that List is the name of some class. Then function f() declares a local List object called x:&lt;br /&gt;void f()&lt;br /&gt;{&lt;br /&gt;List x; // Local object named x (of class List)&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;But function g() declares a function called x() that returns a List:&lt;br /&gt;void g()&lt;br /&gt;{&lt;br /&gt;List x(); // Function named x (that returns a List)&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Can one constructor of a class call another constructor of the same class to initialize the this object?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;A&lt;/span&gt;: Nope. Let's work an example. Suppose you want your constructor Foo::Foo(char) to call another constructor of the same class, say Foo::Foo(char,int), in order that Foo::Foo(char,int) would help initialize the this object. Unfortunately there's no way to do this in C++. Some people do it anyway. Unfortunately it doesn't do what they want. For example, the line Foo(x, 0); does not call Foo::Foo(char,int) on the this object. Instead it calls Foo::Foo(char,int) to initialize a temporary, local object (not this), then it immediately destructs that temporary when control flows over the ;.&lt;br /&gt;&lt;br /&gt;class Foo {&lt;br /&gt;public:&lt;br /&gt;Foo(char x);&lt;br /&gt;Foo(char x, int y);&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;Foo::Foo(char x)&lt;br /&gt;{&lt;br /&gt;...&lt;br /&gt;Foo(x, 0); // this line does NOT help initialize the this object!!&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;You can sometimes combine two constructors via a default parameter:&lt;br /&gt;class Foo {&lt;br /&gt;public:&lt;br /&gt;Foo(char x, int y=0); // this line combines the two constructors&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;If that doesn't work, e.g., if there isn't an appropriate default parameter that combines the two constructors, sometimes you can share their common code in a private init() member function:&lt;br /&gt;class Foo {&lt;br /&gt;public:&lt;br /&gt;Foo(char x);&lt;br /&gt;Foo(char x, int y);&lt;br /&gt;...&lt;br /&gt;private:&lt;br /&gt;void init(char x, int y);&lt;br /&gt;};&lt;br /&gt;Foo::Foo(char x)&lt;br /&gt;{&lt;br /&gt;init(x, int(x) + 7);&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;Foo::Foo(char x, int y)&lt;br /&gt;{&lt;br /&gt;init(x, y);&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;void Foo::init(char x, int y)&lt;br /&gt;{&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;BTW do NOT try to achieve this via placement new. Some people think they can say new(this) Foo(x, int(x)+7) within the body of Foo::Foo(char). However that is bad, bad, bad. Please don't write me and tell me that it seems to work on your particular version of your particular compiler; it's bad. Constructors do a bunch of little magical things behind the scenes, but that bad technique steps on those partially constructed bits. Just say no.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Is the default constructor for Fred always Fred::Fred()?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;A&lt;/span&gt;: No. A "default constructor" is a constructor that can be called with no arguments. One&lt;br /&gt;example of this is a constructor that takes no parameters:&lt;br /&gt;class Fred {&lt;br /&gt;public:&lt;br /&gt;Fred(); // Default constructor: can be called with no args&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;Another example of a "default constructor" is one that can take arguments, provided they are given default values:&lt;br /&gt;class Fred {&lt;br /&gt;public:&lt;br /&gt;Fred(int i=3, int j=5); // Default constructor: can be called with no args&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Which constructor gets called when I create an array of Fred objects?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;A&lt;/span&gt;: Fred's default constructor (except as discussed below.&lt;br /&gt;&lt;br /&gt;class Fred {&lt;br /&gt;public:&lt;br /&gt;Fred();&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;Fred a[10]; calls the default constructor 10 times&lt;br /&gt;Fred* p = new Fred[10]; calls the default constructor 10 times&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;If your class doesn't have a default constructor, you'll get a compile-time error when you attempt to create an array using the above simple syntax:&lt;br /&gt;class Fred {&lt;br /&gt;public:&lt;br /&gt;Fred(int i, int j); assume there is no default constructor&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;Fred a[10]; ERROR: Fred doesn't have a default constructor&lt;br /&gt;Fred* p = new Fred[10]; ERROR: Fred doesn't have a default constructor&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;However, even if your class already has a default constructor, you should try to use std::vector rather than an array (arrays are evil). std::vector lets you decide to use any constructor, not just the default constructor:&lt;br /&gt;&lt;br /&gt;#include&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;std::vector a(10, Fred(5,7)); the 10 Fred objects in std::vector a will be initialized with Fred(5,7)&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Even though you ought to use a std::vector rather than an array, there are times when an array might be the right thing to do, and for those, you might need the "explicit initialization of arrays" syntax. Here's how:&lt;br /&gt;class Fred {&lt;br /&gt;public:&lt;br /&gt;Fred(int i, int j); assume there is no default constructor&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;Fred a[10] = {&lt;br /&gt;Fred(5,7), Fred(5,7), Fred(5,7), Fred(5,7), Fred(5,7), // The 10 Fred objects are&lt;br /&gt;Fred(5,7), Fred(5,7), Fred(5,7), Fred(5,7), Fred(5,7) // initialized using Fred(5,7)&lt;br /&gt;};&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Of course you don't have to do Fred(5,7) for every entry you can put in any numbers you want, even parameters or other variables. Finally, you can use placement-new to manually initialize the elements of the array. Warning: it's ugly: the raw array can't be of type Fred, so you'll need a bunch of pointer-casts to do things like compute array index operations. Warning: it's compiler- and hardware-dependent: you'll need to make sure the storage is aligned with an alignment that is at least as strict as is required for objects of class Fred. Warning: it's tedious to make it exception-safe: you'll need to manually destruct the elements, including in the case when an exception is thrown part-way through the loop that calls the constructors. But if you really want to do it anyway, read up on placementnew. (BTW placement-new is the magic that is used inside of std::vector. The complexity of getting everything right is yet another reason to use std::vector.)&lt;br /&gt;&lt;br /&gt;By the way, did I ever mention that arrays are evil? Or did I mention that you ought to use a std::vector unless there is a compelling reason to use an array?&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-8907623187367084036?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/ZvclrB_2_vF719zQNEKsAlbUZLM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZvclrB_2_vF719zQNEKsAlbUZLM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/ZvclrB_2_vF719zQNEKsAlbUZLM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/ZvclrB_2_vF719zQNEKsAlbUZLM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/8907623187367084036/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions_5997.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/8907623187367084036?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/8907623187367084036?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions_5997.html" title="C++ Interview Questions: Part 3" /><author><name>Jadav Rakesh</name><uri>http://www.blogger.com/profile/16968103720606178461</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://1.bp.blogspot.com/_bmJLwhFyKLo/SZwGI18HsQI/AAAAAAAAAEg/tUBXOiN50GI/S220/Mr.+Rakesh_1.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;A0ICQXg4eip7ImA9WxVQGEQ.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-141512594747264463</id><published>2009-02-05T21:19:00.000-08:00</published><updated>2009-02-05T21:52:40.632-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-05T21:52:40.632-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="constructor" /><category scheme="http://www.blogger.com/atom/ns#" term="C" /><category scheme="http://www.blogger.com/atom/ns#" term="Interview" /><category scheme="http://www.blogger.com/atom/ns#" term="class" /><category scheme="http://www.blogger.com/atom/ns#" term="placement new" /><category scheme="http://www.blogger.com/atom/ns#" term="Questions" /><category scheme="http://www.blogger.com/atom/ns#" term="Answers" /><category scheme="http://www.blogger.com/atom/ns#" term="C++" /><category scheme="http://www.blogger.com/atom/ns#" term="destructor" /><category scheme="http://www.blogger.com/atom/ns#" term="VC++" /><title>C++ Interview Questions: Part 2</title><content type="html">&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Part 2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="font-weight: bold;"&gt;Q: Can I overload the destructor for my class?&lt;/span&gt;&lt;br /&gt;A: No. You can have only one destructor for a class Fred. It's always called Fred::~Fred(). It never takes any parameters, and it never returns anything. You can't pass parameters to the destructor anyway, since you never explicitly call a destructor (well, almost never).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Should I explicitly call a destructor on a local variable?&lt;/span&gt;&lt;br /&gt;A: No! The destructor will get called again at the close } of the block in which the local was created. This is a guarantee of the language; it happens automagically; there's no way to stop it from happening. But you can get really bad results from calling a destructor on the same object a second time! Bang! You're dead!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What if I want a local to "die" before the close } of the scope in which it was created? Can I call a destructor on a local if I really want to?&lt;/span&gt;&lt;br /&gt;A: No! [For context, please read the previous FAQ]. Suppose the (desirable) side effect of destructing a local File object is to close the File. Now suppose you have an object f of a class File and you want File f to be closed before the end of the scope (i.e., the }) of the scope of object f:&lt;br /&gt;&lt;br /&gt;void someCode()&lt;br /&gt;{&lt;br /&gt;File f;&lt;br /&gt;...insert code that should execute when f is still open...&lt;br /&gt;We want the side-effect of f's destructor here!&lt;br /&gt;...insert code that should execute after f is closed...&lt;br /&gt;}&lt;br /&gt;There is a simple solution to this problem. But in the mean time, remember: Do not explicitly call the destructor!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: OK, OK already; I won't explicitly call the destructor of a local; but how do I handle the above situation?&lt;/span&gt;&lt;br /&gt;A: Simply wrap the extent of the lifetime of the local in an artificial block {...}:&lt;br /&gt;void someCode()&lt;br /&gt;{&lt;br /&gt;{&lt;br /&gt;File f;&lt;br /&gt;...insert code that should execute when f is still open...&lt;br /&gt;} f's destructor will automagically be called here!&lt;br /&gt;...insert code here that should execute after f is closed...}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What if I can't wrap the local in an artificial block?&lt;/span&gt;&lt;br /&gt;A: Most of the time, you can limit the lifetime of a local by wrapping the local in an artificial block ({...}). But if for some reason you can't do that, add a member function that has a similar effect as the destructor. But do not call the destructor itself!&lt;br /&gt;For example, in the case of class File, you might add a close() method. Typically the destructor will simply call this close() method. Note that the close() method will need to mark the File object so a subsequent call won't re-close an already-closed File. E.g., it might set the fileHandle_ data member to some nonsensical value such as -1, and it might check at the beginning to see if the fileHandle_ is already equal to -1:&lt;br /&gt;&lt;br /&gt;class File {&lt;br /&gt;public:&lt;br /&gt;void close();&lt;br /&gt;~File();&lt;br /&gt;...&lt;br /&gt;private:&lt;br /&gt;int fileHandle_; // fileHandle_ &gt;= 0 if/only-if it's open&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;File::~File()&lt;br /&gt;{&lt;br /&gt;close();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void File::close()&lt;br /&gt;{&lt;br /&gt;if (fileHandle_ &gt;= 0) {&lt;br /&gt;...insert code to call the OS to close the file...&lt;br /&gt;fileHandle_ = -1;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Note that the other File methods may also need to check if the fileHandle_ is -1 (i.e., check if the File is closed).&lt;br /&gt;Note also that any constructors that don't actually open a file should set fileHandle_ to -1.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: But can I explicitly call a destructor if I've allocated my object with new?&lt;/span&gt;&lt;br /&gt;A: Probably not. Unless you used placement new, you should simply delete the object rather than explicitly calling the destructor. For example, suppose you allocated the object via a typical new expression: Fred* p = new Fred(); Then the destructor Fred::~Fred() will automagically get called when you delete it via: delete p; // Automagically calls p-&gt;~Fred() You should not explicitly call the destructor, since doing so won't release the memory that was allocated for the Fred object itself. Remember: delete p does two things: it calls the destructor and it deallocates the memory.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is "placement new" and why would I use it?&lt;/span&gt;&lt;br /&gt;A: There are many uses of placement new. The simplest use is to place an object at a particular location in memory. This is done by supplying the place as a pointer parameter to the new part of a new expression:&lt;br /&gt;&lt;br /&gt;#include // Must #include this to use "placement new"&lt;br /&gt;#include "Fred.h" // Declaration of class Fred&lt;br /&gt;void someCode()&lt;br /&gt;{&lt;br /&gt;char memory[sizeof(Fred)]; // Line #1&lt;br /&gt;void* place = memory; // Line #2&lt;br /&gt;Fred* f = new(place) Fred(); // Line #3 (see "DANGER" below)&lt;br /&gt;// The pointers f and place will be equal&lt;br /&gt;...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Line #1 creates an array of sizeof(Fred) bytes of memory, which is big enough to hold a Fredobject.&lt;br /&gt;&lt;br /&gt;Line #2 creates a pointer place that points to the first byte of this memory (experienced C&lt;br /&gt;programmers will note that this step was unnecessary; it's there only to make the code moreobvious).&lt;br /&gt;&lt;br /&gt;Line #3 essentially just calls the constructor Fred::Fred(). The this pointer in the Fred&lt;br /&gt;constructor will be equal to place. The returned pointer f will therefore be equal to place.&lt;br /&gt;ADVICE: Don't use this "placement new" syntax unless you have to. Use it only when you really care that an object is placed at a particular location in memory. For example, when your hardware has a memory-mapped I/O timer device, and you want to place a Clock object at that memory location.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;DANGER&lt;/span&gt;: You are taking sole responsibility that the pointer you pass to the "placement new" operator points to a region of memory that is big enough and is properly aligned for the object type that you're creating. Neither the compiler nor the run-time system make any attempt to check whether you did this right. If your Fred class needs to be aligned on a 4 byte boundary but you supplied a location that isn't properly aligned, you can have a serious disaster on your hands (if you don't know what "alignment" means, please don't use the placement new syntax). You have been warned. You are also solely responsible for destructing the placed object. This is done by explicitly calling the destructor:&lt;br /&gt;&lt;br /&gt;void someCode()&lt;br /&gt;{&lt;br /&gt;char memory[sizeof(Fred)];&lt;br /&gt;void* p = memory;&lt;br /&gt;Fred* f = new(p) Fred();&lt;br /&gt;...&lt;br /&gt;f-&gt;~Fred(); // Explicitly call the destructor for the placed object&lt;br /&gt;}&lt;br /&gt;This is about the only time you ever explicitly call a destructor.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Note&lt;/span&gt;: there is a much cleaner but more sophisticated way of handling the destruction / deletion situation.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-141512594747264463?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/J-OlLbbMwpN_Sp3teRy8Qg8aXnc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/J-OlLbbMwpN_Sp3teRy8Qg8aXnc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/J-OlLbbMwpN_Sp3teRy8Qg8aXnc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/J-OlLbbMwpN_Sp3teRy8Qg8aXnc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/141512594747264463/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions_05.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/141512594747264463?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/141512594747264463?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions_05.html" title="C++ Interview Questions: Part 2" /><author><name>Jadav Rakesh</name><uri>http://www.blogger.com/profile/16968103720606178461</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://1.bp.blogspot.com/_bmJLwhFyKLo/SZwGI18HsQI/AAAAAAAAAEg/tUBXOiN50GI/S220/Mr.+Rakesh_1.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;A0EEQ3k9fip7ImA9WxVQGEQ.&quot;"><id>tag:blogger.com,1999:blog-7365152845774153890.post-3612522501118132819</id><published>2009-02-05T20:36:00.001-08:00</published><updated>2009-02-05T21:53:22.766-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-02-05T21:53:22.766-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="constructor" /><category scheme="http://www.blogger.com/atom/ns#" term="C" /><category scheme="http://www.blogger.com/atom/ns#" term="Interview" /><category scheme="http://www.blogger.com/atom/ns#" term="class" /><category scheme="http://www.blogger.com/atom/ns#" term="placement new" /><category scheme="http://www.blogger.com/atom/ns#" term="Questions" /><category scheme="http://www.blogger.com/atom/ns#" term="Answers" /><category scheme="http://www.blogger.com/atom/ns#" term="copy constructor" /><category scheme="http://www.blogger.com/atom/ns#" term="C++" /><category scheme="http://www.blogger.com/atom/ns#" term="destructor" /><category scheme="http://www.blogger.com/atom/ns#" term="VC++" /><title>C++ Interview Questions: Part 1</title><content type="html">&lt;div style="text-align: center;"&gt;&lt;span style="font-weight: bold;"&gt;Part 1&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="font-weight: bold;"&gt;Q: Is it possible to have Virtual Constructor? If yes, how? If not, Why not possible?&lt;/span&gt;&lt;br /&gt;A: There is nothing like Virtual Constructor. The constructor can’t be virtual as the constructor is a code which is responsible for creating an instance of a class and it can’t be delegated to any other object by virtual keyword means.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is Constructor ?&lt;/span&gt;&lt;br /&gt;A: Constructor creates an object and initializes it. It also creates V-Table for virtual functions. It is different from other methods in a class.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What about Virtual Destructor?&lt;/span&gt;&lt;br /&gt;A: Yes there is a Virtual Destructor. A destructor can be virtual as it is possible as at runtime depending on the type of object caller is calling to, proper destructor will be called.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is the difference between a copy constructor and an overloaded assignment operator?&lt;/span&gt;&lt;br /&gt;A: A copy constructor constructs a new object by using the content of the argument object. An overloaded assignment operator assigns the contents of an existing object to another existing object of the same class.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Can a constructor throws an exception? How to handle the error when the constructor fails?&lt;/span&gt;&lt;br /&gt;A: The constructor never throws an error.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is default constructor?&lt;/span&gt;&lt;br /&gt;A: Constructor with no arguments or all the arguments has default values.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is default (Implicit) copy constructor?&lt;/span&gt;&lt;br /&gt;A: Constructor which initializes it's object member variables (by shallow copying) with another object of the same class. If you don't implement one in your class then compiler implements one for you.&lt;br /&gt;Examples:&lt;br /&gt;(a) Boo Obj1(10); // calling Boo constructor&lt;br /&gt;(b) Boo Obj2(Obj1); // calling boo copy constructor&lt;br /&gt;(c) Boo Obj2 = Obj1;// calling boo copy constructor&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: When is copy constructors called?&lt;/span&gt;&lt;br /&gt;A: Copy constructors are called in following cases:&lt;br /&gt;(a) When a function returns an object of that class by value&lt;br /&gt;(b) When the object of that class is passed by value as an argument to a function&lt;br /&gt;(c) When you construct an object based on another object of the same class&lt;br /&gt;(d) When compiler generates a temporary object&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Can a copy constructor accept an object of the same class as parameter, instead of reference of the object?&lt;/span&gt;&lt;br /&gt;A: No. It is specified in the definition of the copy constructor itself. It should generate an error if a programmer specifies a copy constructor with a first argument that is an object and not a reference.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is conversion constructor?&lt;/span&gt;&lt;br /&gt;A: constructor with a single argument makes that constructor as conversion ctor and it can be used for type conversion.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;class Boo&lt;br /&gt;{&lt;br /&gt;        public:&lt;br /&gt;             Boo( int i );&lt;br /&gt;};&lt;br /&gt;Boo BooObject = 10 ; // assigning int 10 Boo object&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q:What is conversion operator??&lt;/span&gt;&lt;br /&gt;A:class can have a public method for specific data type conversions.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;class Boo&lt;br /&gt;{&lt;br /&gt;               double value;&lt;br /&gt;      public:&lt;br /&gt;               Boo(int i )&lt;br /&gt;              operator double()&lt;br /&gt;              {&lt;br /&gt;                    return value;&lt;br /&gt;              }&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Boo BooObject;&lt;br /&gt;double i = BooObject; // assigning object to variable i of type double. now conversion operator gets called to assign the value.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: How can I handle a constructor that fails?&lt;/span&gt;&lt;br /&gt;A: throw an exception. Constructors don't have a return type, so it's not possible to use return codes. The best way to signal constructor failure is therefore to throw an exception.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: How can I handle a destructor that fails?&lt;/span&gt;&lt;br /&gt;A: Write a message to a log-_le. But do not throw an exception. The C++ rule is that you must never throw an exception from a destructor that is being called during the "stack unwinding" process of another exception. For example, if someone says throw Foo(), the stack will be unwound so all the stack frames between the throw Foo() and the } catch (Foo e) { will get popped. This is called stack unwinding. During stack unwinding, all the local objects in all those stack frames are destructed. If one of those destructors throws an exception (say it throws a Bar object), the C++ runtime system is in a no-win situation: should it ignore the Bar and end up in the } catch (Foo e) { where it was originally headed? Should it ignore the Foo and look for a } catch (Bare) { handler? There is no good answer:either choice loses information. So the C++ language guarantees that it will call terminate() at this point, and terminate() kills the process. Bang you're dead.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What is Virtual Destructor?&lt;/span&gt;&lt;br /&gt;A: Using virtual destructors, you can destroy objects without knowing their type - the correct destructor for the object is invoked using the virtual function mechanism. Note that destructors can also be declared as pure virtual functions for abstract classes. if someone will derive from your class, and if someone will say "new Derived", where "Derived" is derived from your class, and if someone will say delete p, where the actual object's type is "Derived" but the pointer p's type is your class.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: Can a copy constructor accept an object of the same class as parameter, instead of reference of the object?&lt;/span&gt;&lt;br /&gt;A: No. It is specified in the definition of the copy constructor itself. It should generate an error if a programmer specifies a copy constructor with a first argument that is an object and not a reference.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What's the order that local objects are destructed?&lt;/span&gt;&lt;br /&gt;A: In reverse order of construction: First constructed, last destructed. In the following example, b's destructor will be executed first, then a's destructor:&lt;br /&gt;void userCode()&lt;br /&gt;{&lt;br /&gt;        Fred a;&lt;br /&gt;        Fred b;&lt;br /&gt;        ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Q: What's the order that objects in an array are destructed?&lt;/span&gt;&lt;br /&gt;A: In reverse order of construction: First constructed, last destructed. In the following example, the order for destructors will be a[9], a[8], ..., a[1], a[0]:&lt;br /&gt;void userCode()&lt;br /&gt;{&lt;br /&gt;        Fred a[10];&lt;br /&gt;        ...&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7365152845774153890-3612522501118132819?l=vc-mfc-interview.blogspot.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/zxGMJx48gPwYCmssxystV39eg2g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zxGMJx48gPwYCmssxystV39eg2g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/zxGMJx48gPwYCmssxystV39eg2g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/zxGMJx48gPwYCmssxystV39eg2g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;</content><link rel="replies" type="application/atom+xml" href="http://vc-mfc-interview.blogspot.com/feeds/3612522501118132819/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/3612522501118132819?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7365152845774153890/posts/default/3612522501118132819?v=2" /><link rel="alternate" type="text/html" href="http://vc-mfc-interview.blogspot.com/2009/02/c-interview-questions.html" title="C++ Interview Questions: Part 1" /><author><name>Jadav Rakesh</name><uri>http://www.blogger.com/profile/16968103720606178461</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="27" height="32" src="http://1.bp.blogspot.com/_bmJLwhFyKLo/SZwGI18HsQI/AAAAAAAAAEg/tUBXOiN50GI/S220/Mr.+Rakesh_1.jpg" /></author><thr:total>0</thr:total></entry></feed>

