P. 1
C

C

|Views: 1|Likes:
Published by Parminder Singh

More info:

Published by: Parminder Singh on Jul 28, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

07/28/2011

pdf

text

original

C++ object-oriented questions

1.

What is a modifier? 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’. Example: The function mod is a modifier in the following code snippet:

2. class test 3. { 4. int x,y; 5. public: 6. test() 7. { 8. x=0; y=0; 9. } 10. void mod() 11. { 12. x=10; 13. y=15; 14. } 15. };

16. What is an accessor? 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

17. Differentiate between a template class and class template.
Template class: A generic definition or a parameterized class not instantiated until the client provides the needed information. It’s jargon for plain templates. 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.

18. When does a name clash occur? 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.

19. Define namespace. 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.

20. What is the use of ‘using’ declaration.
A using declaration makes it possible to use a name from a namespace without the scope operator.

21. What is an Iterator class? A class that is used to
traverse through the objects maintained by a container class. There are five categories of iterators: input iterators, output iterators, forward iterators, bidirectional iterators, random access. 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. The simplest and safest iterators are those that permit read-only access to the contents of a container class.

22. List out some of the OODBMS available. GEMSTONE/OPAL
of Gemstone systems, ONTOS of Ontos, Objectivity of Objectivity Inc, Versant of Versant object technology, Object store of Object Design, ARDENT of ARDENT software, POET of POET software.

23. List out some of the object-oriented methodologies. Object Oriented Development (OOD) (Booch 1991,1994), Object
Oriented Analysis and Design (OOA/D) (Coad and Yourdon 1991), Object Modelling Techniques (OMT) (Rumbaugh 1991), Object Oriented Software Engineering (Objectory) (Jacobson 1992), Object Oriented Analysis (OOA) (Shlaer and Mellor 1992), The Fusion Method (Coleman 1991).

24. What is an incomplete type? 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.

25. 26.

int *i=0x400 // i points to address 400 *i=0; //set the value of memory location pointed by i.
Incomplete types are otherwise called uninitialized pointers.

27. What is a dangling pointer?
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. The following code snippet shows this:

28. class Sample 29. { 30. public: 31. int *ptr; 32. Sample(int i) 33. { 34. ptr = new int(i); }

~Sample() { delete ptr; } void PrintVal() { cout << “The value is ” << *ptr; }

o o Provides response to a message. What is an adaptor class or Wrapper class? A class that has no functionality of its own. It is an implementation of an operation. 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. Differentiate between the message and method. } int main() { Sample s1 = 10. } In the above example when PrintVal() function is called it is called by the pointer that has been freed by the destructor in SomeFunc. A message is sent to invoke a method. . 36. SomeFunc(s1).PrintVal(). s1. 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. What is a Null object? It is an object of some class whose purpose is to indicate that a real object of that class does not exist. void SomeFunc(Sample x) { cout << “Say i am in someFunc ” << endl. Message: o o Method Objects communicate by sending messages to each other. 35.}. 37.

Class invariants must hold when an object is created. }. A class is used correctly if preconditions are never false. The following then becomes legal: Array2D<float>data(10. What do you mean by Stack unwinding? 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. The condition should hold at the end of every mutator (non-const) operation. An operation is not responsible for doing anything sensible if its precondition fails to hold. Define precondition and post-condition to a member function. For example. // fine Here data[3] yields an Array1D object and the operator [] invocation on that object yields the float in . cout<<data[3][6]. What are the conditions that have to be met for a condition to be an invariant of the class? o o The condition should hold at the end of every constructor. { 49. For example. after pushing an element on the stack. public: 50. 43. the interface invariants of stack class say nothing about pushing yet another element on a stack that is already full.20). T& operator[] (int index). In particular all class invariants are both preconditions and post-conditions for all operations or member functions of the class. and they must be preserved under all operations of the class. template <class t=""> 44. We say that isful() is a precondition of the push operation. Array1D operator[] (int index). { 46. Post-condition: 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. class Array1D 48. This is a post-condition of the push operation. const T& operator[] (int index)const. 42. }. What is class invariant? A class invariant is a condition that defines all valid states for an object. const Array1D operator[] (int index) const. 39. 51. public: 47.38. class Array2D 45. A class is implemented correctly if post-conditions are never false. 41. It is a logical condition to ensure the correct working of a class. Precondition: A precondition is a condition that must be true on entry to a member function. 40. we know that isempty() must necessarily hold. What are proxy objects? Objects that stand for other objects are called proxy objects or surrogates.

Sather. 3. ::. conceptually. the container is called a homogeneous container. Orthogonal in the sense means that two classes operate in different dimensions and do not interfere with each other in any way.position(3. ?: Salam in the comments notes that -> can be overloaded. Release decrements reference counter of the object and QueryInterface obtains a pointer to the requested interface. When a container class contains a group of mixed objects. 52. . Objects of this latter class stand for one-dimensional array objects that. Each Array1D object stands for a one-dimensional array that is absent from a conceptual model used by the clients of Array2D. conceptually. Eiffel. 55. A container class is a supporting class whose purpose is to hide the topology used for maintaining the list of objects in memory. COM interview questions 1. Release and QueryInterface functions? AddRef increments reference count of the object. relies primarily on virtual functions in its public interface depends on all its direct and indirect base class can be understood only in the context of the base class can be used as base for further derivation can be used to create objects. What is a container class? What are the types of container classes? A container class is a class that is used to hold objects in memory or external storage.. There are three methods in that interface: AddRef. What is IUnknown? What methods are provided by IUnknown? It is a generally good idea to have an answer for this question if you claim you know COM in your resume. 53. you may consider your interview failed at this point. What should QueryInterface functions do if requested object was not found? Return E_NOINTERFACE and nullify its out parameter. two-dimensional arrays. 56. when the container is holding a group of objects that are all the same. Clients of the Array2D class need not be aware of the presence of the Array1D class. do not exist. 2. .->. provides a wider interface to the users than its base class. The same derived class may inherit such classes with no difficulty. What is a node class? A node class is a class that. . IUnknown is the base interface of COM. o o o o o o o relies on the base class for services and implementation. A node class is a class that has added new services or functionality beyond the services inherited from its base class. 54. sizeof. A container class acts as a generic holder. Release and QueryInterface. the container is called a heterogeneous container. do not exist for clients of Array2D. Smalltalk.*. Name some pure object oriented languages. Such clients program as if they were using real.6) of the original two dimensional array. All other interfaces must derive directly or indirectly from IUnknown. Name the operators that cannot be overloaded. live. In the above example. Its instances stand for one-dimensional arrays that. or orthogonal to each other. Otherwise. A container class has a predefined behavior and a well-known interface. What are the purposes of AddRef. . Array1D is a proxy class. What is an orthogonal base class? If two base classes have no overlapping methods or data they are said to be independent of. Java.

because OLE was built over COM for years. Instead of accessing such an object remotely. What is a multi-threaded apartment (MTA)? Single-threaded apartment (STA)? This is pretty difficult question to describe shortly. while COM as a technology was presented by Microsoft a few years ago. Therefore. 19. 15. all depends on the level of detail and expertise of interviewer. between OLE and COM? OLE is build on top of COM. 11. it all depends on your project.) DCOM introduced a load balancing. IDualInterface1). 16. Further details would depend on a specific situation. and is available as a convenience to avoid extra implementation overhead in the outer object in these cases. DCOM introduced several improvements/optimizations for distributed environment. Start with simple explanation of class object and class factory mechanism. 17. If interviewer is still not satisfied. including a difference between local server and inproc server. in which the outer object exposes interfaces from the inner object as if they were implemented on the outer object itself. The caller won’t be able to notice the difference. This is useful when the outer object would always delegate every call to one of its interfaces to the same interface in the inner object. will delegate request for the interface to C. What is a moniker ? An object that implements the IMoniker interface. a moniker identifies a COM object in the directory namespace. Start your answer from CoCreateInstance or CoCreateInstanceEx. while OLE is a particular implementation of this specification. Anyway. What is marshalling by value? Some objects can essentially be considered static: regardless of which methods are called. if any. you’ll have to explain the whole kitchen behind the scenes. the state of the object does not change. What is aggregation? How can we get an interface of the aggregated object? Aggregation is the reuse mechanism. You may also mention other methods of object creation like CoGetInstanceFromFile. The question is not strict. one should use CoCreateInstanceEx. What is a dual interface? Dual interface is one that supports both . Can you have two dual interfaces in one class? Yes. 12. apartments were introduced by Microsoft in NT 3. 8. A moniker acts as a name that uniquely identifies a COM object. etc. it might be used in scripting environment like VBScript and yet to use power and speed of vtbl-based interface for non-scripting environment. Discussion then may easily transform into analyzing of dual interface problems . This is called “marshaling by value". Any DCOM object is yet a COM object (DCOM extends COM) and any COM object may participate in DCOM transactions. calling QueryInterface of the outer object with IID of the inner interface. it is possible to copy the static state of the object and create a new object with the same state information on the caller side. dim dim set set d1 d2 d1 d2 as IDualInterface1 as IDualInterface2 = new MyClassWithTwoDuals = d1 In ATL’s class you would have to use macro COM_INTERFACE_ENTRY2(IDispatch. the question does not require strict answer. 9. 10.be prepared to this twist. What happens when client calls CoCreateInstance? Again. security contexts etc. 13. C is aggregated by B. To create a remote object or to get several objects. 7. explain the difference between them. which in turn aggregated by A. What the limitations of CoCreateInstance? Well. Our client requested C.IDispatch interface and vtbl-based interface. In the same way that a path identifies a file in the file system. What’s the difference. You need a surrogate process to do that. You may mention also that COM is a specification. Aggregation is actually a specialized case of containment/delegation. which in today’s world is not exactly true as well. 18. How can would you create an instance of the object in COM? Well. but calls will be more efficient because they do not involve network round trips. We can get a pointer to the inner interface. DCOM demonstrated importance of surrogate process (you cannot run in-proc server on a remote machine. 5. You may have two dual interfaces in one class. This pointer will be returned to the client. but discussion will likely turn to discussion of monikers then. 6. What will happen? QueryInterface to A will delegate request to B which.4. The bottom line is that you cannot work with two dual interfaces at the same time due to nature of dual interface! To support two dual interfaces in VB you would write something like: 14. in turn.51 and late Windows 95 to isolate the problem of running legacy . at the same time. meaning and mechanism of class factory. to distinguish between different dual interfaces. but only one of them may be default. based on single CLSID. the major problems with CoCreateInstance is that it is only able to create one object and only on local system. such as MULTI_QI (multiple QueryInterface()). What’s the difference between COM and DCOM? Again. because what people call COM today is likely implementation of COM spec by Microsoft.

How can you guarantee that only remote server is ever created by a client? Create an object (call CoCreateObjectEx()) with CLSCTX_REMOTE_SERVER flag.0. The reason to create an object in apartment is thread-safety. COM object that implemented as DLL and supposed to be hosted by a container. The most famous examples are probably drag and drop and structured storage implementations. you may use DLLHost. or free threading apartment) were introduced in NT 4. See “Professional DCOM Programming” of Dr. What is an IDL? IDL stands for Interface Definition Language. created by B.doc document a compound document? Is it a structured storage? Compound document is a document that contains information about other documents hosted in this document. In MTA the developer is responsible for that.exe? Yes. The . What is In-proc? In-proc is in-process COM object. Is there a way to register in-proc server without regsvr32. Global Interface Table (GIT) allows any apartment (either single. 26.e. 20. 23. i. Call DllRegisterServer() from the client. i. Contained object is created within the object container and its interfaces might be altered or filtered by the object container. running object table (ROT) is a globally accessible table on each computer that keeps track of all COM objects in the running state that can be identified by a moniker. All office documents _may_ be compound documents. Aggregated object exposes its interface directly. 27. 32. QI’ing for IUnknown you may proceed and to get a pointer to any other interface. its moniker must be released from the table. The biggest disadvantage of VARIANT is size of the union. If you have an object with two interfaces. By definition. What is VARIANT? Why and where would you use it? VARIANT is a huge union containing automation type. but may be not. What is __declspec(novtable)? Why would you need this? __declspec(novtable) is a Microsoft’s compiler optimization. Let’s assume we have object B and aggregated object C (in-proc server). 22. while it is initialized in contructor) MSDN has an article on this topic. IDL is the language to describe COM interfaces. Is . or “Essential COM” of Don Box for the further discussion on this topic. Word documents from version 6. You may also use Registrar object for the same purpose or use direct manipulation of the windows registry. 29.non-thread safe code into multithreaded environment. Can you access any interface of B from C? What’s the difference between aggregated and contained objects? Yes. This is fundamental postulate of COM: “If you can get there from here. What is OLE? OLE is an object and embedding first implementation of COM spec available from MS before COM was officially named COM. Intel interview questions 1. 31. you can get there from anywhere". What are 2 storage types for composite document? Storage and Stream. The main idea of this optimization is to strip the vtable initialization code from abstract class (for abstract class the vtable is empty. without visible intervention of the object container. This allows easy conversion of one automation type to another. 25.e. which increments the object’s reference count. Each thread was “encapsulated” into so called single-threaded apartment. you can. 24. Before the object can be destroyed.0 and up are stored as structured storage. 30. Give examples of OLE usage. 28. 21. Idea behind MTA is that COM is not responsible to synchronize object calls between threads. When you have to instantiate the in-proc object remotely. can you custom marshal one of them? No! The decision to use custom marshaling is an all-or-nothing decision.or multi-threaded) in a process to get access to an interface implemented on an object in any other apartment in the process. COM is responsible synchronize access to the object even if the object inside of the apartment is not thread-safe. Grimes et al. What is ROT ? GIT ? Count pros and cons of both. supported by the object. Do not forget to call DLLUnregisterServer() from the same client. Moniker providers register an object in the table. an object has to custom marshal all its interfaces or none of them. Multithreaded apartments (MTA.exe application that was design specially for this purpose. The following questions are used for screening the candidates during the first interview.

1. What are the main issues associated with multiprocessor caches and how might you solve them? Explain the difference between write through and write back cache. what can be done to correct this problem? 13. 7. What compiler was used? 15. What was your role in the silicon evaluation/product ramp? What tools did you use? 25.Software Quality Assurance) position. 5. Have you studied buses? What types? Have you studied pipelining? List the 5 stages of a 5 stage pipeline. 4. Describe a finite state machine that will detect three consecutive coin tosses (of one coin) that results in heads. what is the purpose of a processor cache and describe its operation? Explain the operation considering a two processor computer system with a cache for each processor. What types of I/O have you designed? What were their size? Speed? Configuration? Voltage requirements? 20. 8. Are you familiar with the term MESI? Are you familiar with the term snooping? 3. 2. The questions were asked by Lucent Technologies for Software Tester (in some companies SQA . What types of CMOS memories have you designed? What were their size? Speed? 18. You have a driver that drives a long signal & connects to an input device. What is the difference between = and == in C? 16. . Are you familiar with VHDL and/or Verilog? 17. What transistor level design tools are you proficient with? What types of designs were they used on? 23. 9. What products have you designed which have entered high volume production? 24. If not into production.questions apply mostly to fresh college grads pursuing an engineering career at Intel. What work have you done on full chip Clock and Power distribution? What process technology and budgets were used? 19. Assuming 1 clock per stage. At the input device there is either overshoot. what is the latency of an instruction in a 5 stage machine? What is the throughput of this machine ? How many bit combinations are there in a byte? For a single computer processor computer system. 10. undershoot or signal threshold violations. In what cases do you need to double clock a signal before presenting it to a synchronous state machine? 12. Process technology? What package was used and how did you model the package/system? What parasitic effects were considered? 21. 6. What are the total number of lines written by you in C/C++? What is the most complicated/valuable program written in C/C++? 14. how far did you follow the design and why did not you see it into production? Software tester interview questions 1. 11. What types of high speed CMOS circuits have you designed? 22.

How long would you stay with us? 30. Do you like music? Which composers are your favourite? 16. What security tools have you used? 20. Tell me about your experience with this type of work 22. What programming language are you using? What C++ libraries are you proficient with? Which argorithm do you like the most? Why? How do you debug SSH? What is the QA process? How do you train another QA engineer? What bug tracking tools you have used? Have you used any free tools? How do you start your QA if there are no system requirements? Have you used MSVC? What do you think of it? 10. 7. Why do you think you are suited for this job? 13. What makes you think you are qualified for this job? 15. What is your weakness? 12. Are you thinking of going back to school or college? . 28. How long whould it take you to make a meaningful contribution to our firm? 29. Please give me your definition of software test engineer. Why do you want to work for us? 24. When will you be available to start work? 19. what will you do? 14. 21. 6. If there is a day. 4. 3. when you find yourself not fitting in our team. if you only enter into the light room once. What kind of PC games you like most? Why? 17.1. Are you familiar with collboration tools? Which communication method do you prefer for talk. 9. How can you find out which switch corresponds to which light? 11. What is the job’s most attractive and least attractive factor? 26. 8. email and chat? 18. 2. What do you look for in a job? 27. There are 3 lights (in one room) and 3 swtiches (in another room). Tell me about yourself. one for each. What should we hire you? What can you do for us? What can you do that others can not? 25. 5. What do you like and dislike about our company? 23.

local and register variables? 15. What was your last employer’s opinion of you? 35. Give me an example of a project you handled from start to finish. 3. Out of fgets() and gets() which function is safe to use and why? 19. No answers. 2. 1. free memory and C Program instructions get stored? 12. Can we specify variable field width in a scanf() format string? If possible how? 18. Difference between arrays and linked list? 13. local. register variables. What is recursion? 21. What are register variables? What are the advantage of using register variables? 16. A frequent reader of this site sent this in. What are the different storage classes in C? . 5. deadline etc? 36. Consider getting Kernighan and Ritchie title if you find many things puzzling here. Differentiate between a for loop and a while loop? What are it uses? 22. You may be overqualified for this position we have to offer. Difference between strdup and strcpy? 20. What is the use of typedef? 17.31. Can you work under pressure. Do you have any questions? 37. 8. 6. 33. 4. Where does global. but a nice set of questions. 34. What is it you liked and disliked about your last job? C interview questions 1. static. Where are the auto variables stored? 11. Describe about storage allocation and scope of global. What kind of programs/machines or equipment have you worked with? 32. 9. What are enumerations? 14. 7. extern. static. What does static variable mean? What is a pointer? What is a structure? What are the differences between structures and arrays? In header files whether functions are declared or defined? What are the differences between malloc() and calloc()? What are macros? What are the advantages and disadvantages? Difference between pass by reference and pass by value? What is static identifier? 10.

Are the variables argc and argv are local to main? 47. What are the advantages of using pointers in a program? 27. In a header file whether functions are declared or defined? 29. How are Structure passing and returning implemented by the complier? 43.23. To which numbering system can the binary number 1101100100111100 be easily converted to? . What do the ‘c’ and ‘v’ in argc and argv stand for? 46. Explain one method to process an entire string as one unit? 39. What does the error ‘Null Pointer Assignment’ mean and what causes this error? 34. which? 49. What is the maximum combined length of command line arguments including the space between adjacent arguments? 48. What is near. What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro? 33. How can we read/write Structures from/to data files? 44. Does mentioning the array name gives the base address in all the contexts? 38. What the advantages of using Unions? 26. What is a NULL Pointer? Whether it is same as an uninitialized pointer? 32. Can a Structure contain a Pointer to itself? 41. Write down the equivalent pointer expression for referring the same element a[i][j][k][l]? 24. What is the difference between an enumeration and a set of pre-processor # defines? 45. far and huge pointers? How many bytes are occupied by them? 35. How would you obtain segment and offset addresses from a far address of a memory location? 36. What is a far pointer? where we use it? 30. What is difference between Structure and Unions? 25. What is the similarity between a Structure. What is the difference between Strings and Arrays? 28. Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function? 50. are we required to make any special provision? If yes. If we want that any wildcard characters in the command line arguments should be appropriately expanded. How can we check whether the contents of two structure variables are same or not? 42. Union and enumeration? 40. Are the expressions arr and *arr same for an array of integers? 37. How will you declare an array of three function pointers where each function receives two ints and returns a float? 31. What are bit fields? What is the use of bit fields in a Structure declaration? 51.

What are the advantages of using typedef in a program? 67. When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically? 71. How do you declare the following:    An array of three pointers to chars An array of three char pointers A pointer to array of three chars . Write programs for String Reversal. etc. 60. How can a called function determine the number of arguments that have been passed to it? 78. 61. strcpy(). How can you increase the size of a statically allocated array? 70. Which bit wise operator is suitable for turning off a particular bit in a number? 54. Which one is equivalent to multiplying by 2?   Left shifting a number by 1 Left shifting an unsigned int or char by 1? 57. How would you dynamically allocate a one-dimensional and two-dimensional array of integers? 68. Which bit wise operator is suitable for checking whether a particular bit is on or off? 53.52. Which bit wise operator is suitable for putting on a particular bit in a number? 55. Write a program which uses command line arguments. 58. Write a program to compare two strings without using the strcmp() function. 62. Write a program which employs Recursion? 64. Write a program which uses functions like strcmp(). Can there be at least some solution to determine the number of arguments passed to a variable argument list function? 79. Write a program to find the Factorial of a number. Can you dynamically allocate arrays in expanded memory? 74. What is object file? How can you access object file? 75. Write a program to generate the Fibonacci Series? 63. Which function should be used to free the memory allocated by calloc()? 72. 66. Write a program to interchange 2 variables without using the third one. 65. Which bit wise operator is suitable for checking whether a particular bit is on or off? 56. Write a program to concatenate two strings. Which header file should you include if you are to develop a function which can accept variable number of arguments? 76. Can you write a function similar to printf()? 77. How can you increase the size of a dynamically allocated array? 69. 59. How much maximum can you allocate in a single call to malloc()? 73. The same for Palindrome check.

How would you use qsort() function to sort an array of structures? 83. How would you implement a substr() function that extracts a sub string from a given string? 91. Can you use the function fprintf() to display the output on the screen? 95. How would you use qsort() function to sort the name stored in an array of pointers to string? 84. ask him to declare a pointer to a single character. How would you use the functions randomize() and random()? 90. How do you print a string on the printer? 94. How do you detect a loop in linked list? 97. If he says this is a string declaration. Explain which of the following declarations will compile and what will be constant . } C++ gamedev interview questions 1. What do the functions atoi(). How would you obtain the current time and difference between two times? 89. freed(). ajz at his interviews asks what will be printed out when the following code is executed: main() { printf("%x". sqrt()? 86. fwrite() and ftell()? 88. Sunil asks: What is the difference between main() in C and main() in C++? 98. itoa() and gcvt() do? 81. How would you use the functions memcpy().-1<<4). random(). How would you use bsearch() function to search a name stored in array of pointers to string? 85. Both explanations are correct. Gautam Pagedar adds this question: What is a linklist and why do we use it when we have arrays? . As you can see. What is the difference between the functions memmove() and memcpy()? 93. memmove()? 87.I feel the correct answer should be linklist is used in cases where you don’t know the memory required to store a data structure and need to allocate is dynamically on demand. What is the difference between the functions rand().a pointer or the value pointed at:    const char * char const * char * const Note: Ask the candidate whether the first declaration is pointing to a string or a single character. How would you use the functions fseek(). 96. srand() and randomize()? 92. Does there exist any other function which can be used to convert an integer or a float to a string? 82. the answers are not given (the interviews are typically conducted by senior developers). memset(). Competent . pow(). but there’s a set of notes with common mistakes to avoid. 1. This set of questions came from a prominent gaming company.  A pointer to function which receives an int pointer and returns a float pointer A pointer to a function which receives nothing and returns nothing 80. How would you use the functions sin(). ask why a whole string is initialized as char* in C++. but if he says that it’s a single character pointer.

struct C { C(){ cout << "C". The candidate does not understand pointers. } }. Consider the following struct declarations: 5. } }. The candidate might also want to return a pointer. Explain virtual inheritance. struct B { B(){ cout << "B". C c. “The entire array will be deleted. delete p. } }. Write the following functions:     Copy constructor = operator overload == operator overload + operator overload (customers’ balances should be added up. A very smart candidate will ask whether delete is overloaded for the class T. 15. incompetent ones will come up with invalid reasons. where a single base class is inherited with virtual methods. 22. Ask them for the classic . struct E : D { E(){ cout << "E". 14. { 12. in the first case. 7.e() { cout << "F". Explain to the candidate that this is not virtual inheritance. 2. Draw the diagram explaining the initialization of the base class when virtual inheritance is used. Note: Typical wrong answer: Yes. What problems might the following macro bring to the application? #define sq(x) x*x 4. from the addition operator. T *p = new T[10]. Anything wrong with this code? 20. What constructors will be called when an instance of F is initialized? Produce the program output when this happens. E e. Note: Typical mistake for applicant is to draw an inheritance diagram. 19. 21. D d. struct F : A. the program will crash in an attempt to delete a null pointer. struct A { A(){ cout << "A". The applicant might make a mistake of passing by value. everything is correct". “Only the first element of the array will be deleted". too. 9.c(). struct D { D(){ cout << "D". 3. Note: Incorrect replies: “No. 8. Ask him whether the statement customer3 = customer1 + customer2 would work in the second case. You’re given a simple code for the class BankCustomer. } }. Anything wrong with this code? 17. 18. T *p = 0. 6. not by reference.d().candidates should not have problems pointing out why const char* can be both a character and a string declaration. but only the first element destructor will be called". B 11. } }. } }. Slightly hint that you’d like the value to be changed outside the function. 13. delete p. A(). not a new object. 10. as an example of joint account between husband and wife) Note:Anyone confusing assignment and equality operators should be dismissed from the interview. F() : B(). 16.

32. 4. 38. Note: Hint to the candidate about the base platform they’re developing for. }. 31. 37. case 3: *to++ = *from++. 42. 29. Such question might be too complex for a beginning or even intermediate developer. What’s potentially wrong with the following code? 24. Moreover. 1. 6. 5. Good C++ Interview questions 1. case 5: *to++ = *from++. 25. 3. 34. even though he’ll probably say he’d avoid using it in a real project. 45. How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters? . who know about virtual inheritance. long value. 33. In the H file you see the following declaration: Tell me all you know about the Bar() function. What does the following code do and why would anyone write something like that? 28. case 6: *to++ = *from++. 46. he’s hired. they are not experienced with C++. } } class Foo { void Bar( void ) const . 41. 39. case 2: *to++ = *from++. How do you decide which integer type to use? What should the 64-bit integer type on new. TSome good C++ questions to ask a job applicant. 26. If you find a candidate that knows both the concept and the initialization process well.definition of virtual inheritance. //some stuff value &= 0xFFFF. 44. If the person still doesn’t find anything wrong with the code. 7. int * from. cannot coherently explain the initialization process. case 1: *to++ = *from++. 36. 40. even the experienced developers. void send (int *to. 27. 47. case 7: *to++ = *from++. 35. int count) { int n = (count + 7) / 8. 23. 43. but any applicant with advanced C++ experience should be somewhat familiar with the concept. 2. 64-bit machines be? What’s the best way to declare and define global variables? What does extern mean in a function declaration? What’s the auto keyword good for? I can’t seem to define a linked list node which contains a pointer to itself. 30. case 4: *to++ = *from++. switch ( count % 8) { case 0: do { *to++ = *from++. } while ( --n > 0 ).

x. x=y++ + x++.y).1 4. y=10. . y= ++y + ++x. How do I initialize a pointer to a function. 0. What will print out? main() { char *p1=“name”. What will be printed as the result of the operation below: main() { int x=5.b=a-b. ? 13.%d. What can I safely assume about the initial values of variables which are not explicitly initialized? 11. void main() { int x=5. printf(“%sn”.x>>2). ow can I declare a function that returns a pointer to a function of its own type? My compiler is complaining about an invalid redeclaration of a function. 2.b) a=a+b. and char *p = “string". char *p2. C interview questions part1 1. 20). 9. but I only define it once and call it once.a=a-b.%dn”. } Answer:empty string. memset (p2.x.20. What’s happening? 10. swap (x. printf(“%d%dn”.y). p2=(char*)malloc(20). } Answer : 5794 3.x< <2. printf(“%d.p2). while(*p2++ = *p1++). What will be printed as the result of the operation below: #define swap(a. } Answer: 5. Why can’t I initialize a local array with a string? 12. What is the difference between char a[] = “string".y=35. What will be printed as the result of the operation below: main() { int x=20.8.

swap2(x. } Answer: 10. printf(“%d %dn”.y). } Answer: Cisco 7. b=a.printf(“%d %dn”. strcat(p1. return 0.x. char *p2. strcpy(p1. printf(“%sn”.y).x. char s2[]= “systems”. p2=(char *)malloc(25). a=temp. 5 10. } . ptr++. 5 5.ptr). What will be printed as the result of the operation below: main() { char *p1.y).p1). What will be printed as the result of the operation below: main() { char s1[]=“Cisco”.ptr).s1). temp=a.“systems”). *ptr++.”Cisco”). printf(“%s”. printf(“%sn”. printf(“%s”. } Answer:Cisco Systems isco systems 6. p1=(char *)malloc(25).p2). int b) { int temp. strcpy(p2. What will be printed as the result of the operation below: main() { char *ptr = ” Cisco Systems”. } int swap2(int a.

c can access the variable. x++. printf("First output:%dn". who can access it?: 9. y = ++y. x++. Answer: all the functions in the file1. modifyvalue(). changevalue(x).c.x). printf("Second output:%dn". printf(“%d %dn”. int modifyvalue() { return(x+=10). 11. static int average. 13 . x = x++. What will be printed as the result of the operation below: main() { int x=10. } int changevalue(int x) { return(x+=1). x++. changevalue(x). printf("Third output:%dn". } void main() { int x=10. .y). 10. modifyvalue(). WHat will be the result of the following code? #define TRUE 0 // some code while(TRUE) { // some code } Answer: This will not go into the loop as TRUE is defined as 0.x).Answer: Ciscosystems 8. 13 12. What will be printed as the result of the operation below: int x. The following variable is available in file1. y=15. } Answer: 12 .x.x).

3) does not expand but gives preprocessor warning. #define cat(x. 3. 6. Can you have constant volatile variable? Yes. But cat(cat(1. 5. printf(“Cisco Systemsn”). What will be printed as the result of the operation below: main() { int a=0. Embedded systems interview questions 1. ++*ip increments what? it increments what ip points to 18. 16 13. if(a==0) printf(“Cisco Systemsn”). Order of constructor and destructor call in case of multiple inheritance? 12. Why? 16.2). } Answer: Two lines with “Cisco Systems” will be printed. Is java a pure object oriented language? Why? 11.objects contain howmany multiply inherited ancestor? What are the 4 different types of inheritance relationship? How would you find out the no of instance of a class? 10. Can structures be passed to the functions by value? Why cannot arrays be passed by values to functions? Advantages and disadvantages of using macro and inline functions? What happens when recursion functions are declared inline? Scope of static variables? Difference between object oriented and object based languages? Multiple inheritance . 8.y) x##y concatenates x to y. -> ef 15. What is the output of printf("\nab\bcd\ref"). 7. 4. 2. When you inherit a class using private keyword which members of base class are visible to the derived class? 14. you can have a volatile pointer? 17.} Answer: 11. 9. a+++b -> (a++)+b . Operations involving unsigned and signed – unsigned will be converted to signed 19. Can u have inline virtual functions in a class? 13.

How is generic list manipulation function written which accepts elements of any kind? 30. cout << i<<". How is function itoa() written? 26. Transport. How can you define a structure with bit field members? 34. # error – what it does? 25. 24. What is the differnce between embedded systems and the system in which rtos is running? 33. for( unsigned int i = 1.fork().t. What are the different BSD and SVR4 communication mechanisms C++ code examples for job interviews 1. if((numb <5)&&(numb>9)) . Who to know wether systemuses big endian or little endian format and how to convert among them? 27. Presentation. 22. int average=0. i++ ) 3.r.Q: Write a program that ask for user input from 5 to 9 then calculate the average( Asked A. The IP is operated in the Ne 3. Array of pts to functions – void (*fptr[10])() 23. What is interrupt latency? 28. What is forward reference w. i < = 100. What are the different storage classes in C? 37. pointers in c? 29. } – will print 8 times.int main() { int MAX=4.printf("hello world"). What are the features different in pSOS and vxWorks? 35. Q: Write a short code using C++ to print out all odd number from 1 to 100 using a for loop( 2.a byte and a field in the byte and returns the value of the field in that byte? 36. What is the difference between hard real-time and soft real-time OS? 31. main() {fork(). ISO layers and what layer is the IP operated from?( Asked by Cisco system people) cation. int numb.". What is interrupt latency? How can you recuce it? 32. Data link and Physical. malloc(sizeof(0)) will return – valid pointer 21. if( i & 0x00000001 ) 4.20. cin>>numb.fork(). How do you write a function which takes 2 arguments . Session. int total =0. Network. Which way of writing infinite loops is more efficient than others? there are 3ways. What are the different qualifiers in C? 38. cout<<"Please enter your input from 5 to 9".

i<=MAX. } cout<<"The average number is"<<average<<endl. 5.cout<<"please re type your input".Q: If you hear the CPU fan is running and the monitor power is still on. Straight-through is type of wiring that is one to to one connection Cross. return 0. average= total /MAX. else for(i=0.through and Cross-over? (Asked by Cisco system people) A. } 4.over is type of wiring whi We use Straight-through cable when we connect between NIC Adapter and Hub. Using Cross-over cab Adapters or sometime between two hubs. but you did not se monitor screen. I would use the ping command to check whether the machine is still alive(connect to the network) .over cable wiring? an Straight. i++) { total = total + numb. What would you do to find out what is going wrong? (Asked by WNI people A.through and Cross.Q: Can you be bale to identify between Straight.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->