- New Updates Alerts-Subscribe

Our Telegram Channel - Join Us

Our Free Email Alerts - Join Us

Important Note:Login & Check Your
Email Inbox and Activate Confirmation Link

Our Whatsapp Group - Join Us

Technical Interview Materials PDF-Free Download

Technical Interview Q & A PDF

• Question 17. Explain The Scope Resolution Operator.?

Answer :

The scope resolution operator 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. 

The answer can get complicated. It should start with “colon-colon,” however. (Some readers had not heard the term, “scope resolution operator,” but they knew what :: means. You should know the formal names of such things so that you can understand all communication about them.) If you claim to be well into the design or use of classes that employ inheritance, you tend to address overriding virtual function overrides to explicitly call a function higher in the hierarchy. That’s good knowledge to demonstrate, but address your comments specifically to global scope resolution. Describe C++’s ability to override the particular C behavior where identifiers in the global scope are always hidden by similar identifiers in a local scope. 

• Question 18. What Are The Differences Between A C++ Struct And C++ Class?

Answer :

The default member and base class access specifiers are different.

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 you because you will be in plenty of good company. Getting it right is a definite plus. 

• Question 19. How Many Ways Are There To Initialize An Int With A Constant?

Answer :

There are two formats for initializers in C++ as shown in Example 1. Example 1(a) uses the traditional C notation, while Example 1(b) uses constructor notation. Many programmers do not know about the notation in Example 1(b), 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. 

A reader wrote to tell me of two other ways, as shown in Examples 2(a) and 2(b), which made me think that maybe the answer could be extended even further to include the initialization of an int function parameter with a constant argument from the caller. 

• Question 20. How Does Throwing And Catching Exceptions Differ From Using Setjmp And Longjmp?

Answer :

The throw operation calls the destructors for automatic objects instantiated since entry to the try block.

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. It’s okay to discuss the notational differences between the two idioms. Explain the syntax of try blocks, catch exception handlers, and throw expressions. Then specifically address what happens in a throw that does not happen in a longjmp. Your answer should reflect an understanding of the behavior described in the answer just given. One valid reason for not knowing about exception handling is that your experience is exclusively with older C++ compilers that do not implement exception handling. I would prefer that you have at least heard of exception handling, though. 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, you 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 to the interviewer a lot about your overall understanding of C++. 

• Question 21. What Is Your Reaction To This Line Of Code?

Answer :

delete this;

It’s not a good practice.

A good programmer will insist that the statement is never to be used if the class is to be used by other programmers and instantiated as static, extern, or automatic objects. That much should be obvious. 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. A reader pointed out that a class can ensure that its objects are instantiated on the heap by making its destructor private. This idiom necessitates a kludgy DeleteMe kind of function because the instantiator cannot call the delete operator for objects of the class. The DeleteMe function would then use “delete this.” I got a lot of mail about this issue. Many programmers believe that delete this is a valid construct. In my experience, classes that use delete this when objects are instantiated by users usually spawn bugs related to the idiom, most often when a program dereferences a pointer to an object that has already deleted itself. 

• Question 22. What Is A Default Constructor?

Answer :

A constructor that has no arguments or one where all the arguments have default argument values.

If you don’t code a default constructor, 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. • Question 23. What Is A Conversion Constructor?

Answer :

A constructor that accepts one argument of a different type.

The compiler uses this idiom as one way to infer conversion rules for a 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 the type and sees an object of the type of the constructor’s first argument. 

• Question 24. What Is The Difference Between A Copy Constructor And An Overloaded Assignment Operator?

Answer :

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. First, you must know that a copy constructor is one that has only one argument, which is a reference to 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. 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. This discussion is a good place to get into why classes need copy constructors and overloaded assignment operators. By discussing the requirements with respect to data member pointers that point to dynamically allocated resources, you demonstrate a good grasp of the problem. 

• Question 25. When Should You Use Multiple Inheritance?

Answer :

There are three acceptable answers: “Never,” “Rarely,” and “When the problem domain cannot be accurately modeled any other way.” There are some famous C++ pundits and luminaries who disagree with that third answer, so be careful. 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 an intuitive way to model this common problem domain. You 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. Stress this understanding because your interviewer might share the common bias against multiple inheritance that many object-oriented designers hold. 

• Question 26. What Is A Virtual Destructor?

Answer :

The simple answer is that a virtual destructor is one that is declared with the virtual attribute.

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. 

• Question 27. Explain The Isa And Hasa Class Relationships. How Would You Implement Each In A Class Design? 

Answer :

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. The answer to this question reveals whether you have an understanding of the fundamentals of object-oriented design, which is important to reliable class design. 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 onscreen, for example. But if you get ISA and HASA right, you usually don’t need to go any further. 

• Question 28. When Is A Template A Better Solution Than A Base Class?

Answer :

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

• Question 29. What Is The Difference Between C And C++ ? Would You Prefer To Use One Over The Other ?

Answer :

C is based on structured programming whereas C++ supports the object-oriented programming paradigm.Due to the advantages inherent in object-oriented programs such as modularity and reuse, C++ is preferred. However almost anything that can be built using C++ can also be built using C. 

• Question 30. What Are The Access Privileges In C++ ? What Is The Default Access Level ?

Answer :

The access privileges in C++ are private, public and protected. The default access level assigned to members of a class is private. Private members of a class are accessible only within the class and by friends of the class. Protected members are accessible by the class itself and it’s sub-classes. Public members of a class can be accessed by anyone. 

• Question 31. What Is Data Encapsulation ?

Answer :

Data Encapsulation is also known as data hiding. The most important advantage of encapsulation is that it lets the programmer create an object and then provide an interface to the object that other objects can use to call the methods provided by the object. The programmer can change the internal workings of an object but this transparent to other interfacing programs as long as the interface remains unchanged. 

• Question 32. What Is Inheritance ?

Answer :

Inheritance is the process of deriving classes from other classes. In such a case, the sub-class has an ‘is-a’ relationship with the super class. For e.g. vehicle can be a super-class and car can be a sub-class derived from vehicle. In this case a car is a vehicle. The super class ‘is not a’ sub-class as the sub- class is more specialized and may contain additional members as compared to the super class. The greatest advantage of inheritance is that it promotes generic design and code reuse. 

• Question 33. What Is Multiple Inheritance ? What Are It’s Advantages And Disadvantages ?

Answer :

Multiple Inheritance is the process whereby a sub-class can be derived from more than one super class. The advantage of multiple inheritance is that it allows a class to inherit the functionality of more than one base class thus allowing for modeling of complex relationships. The disadvantage of multiple inheritance is that it can lead to a lot of confusion when two base classes implement a method with the same name. 

• Question 34. What Do The Keyword Static And Const Signify?

Answer :

When a class member is declared to be of a static type, it means that the member is not an instance variable but a class variable. Such a member is accessed using Classname.Membername (as opposed to Object.Membername). Const is a keyword used in C++ to specify that an object’s value cannot be changed. 

• Question 35. How Is Memory Allocated/deallocated In C ? How About C++ ?

Answer :

Memory is allocated in C using malloc() and freed using free(). In C++ the new() operator is used to allocate memory to an object and the delete() operator is used to free the memory taken up by an object. 

• Question 36. What Is Uml?

Answer :

UML refers to Unified Modeling Language. It is a language used to model OO problem spaces and solutions.

• Question 37. What Is The Difference Between A Shallow Copy And A Deep Copy?

Answer :

A shallow copy simply creates a new object and inserts in it references to the members of the original object. A deep copy constructs a new object and then creates in it copies of each of the members of the original object. 

1)Who invented C Language?

Dennis Ritchie in 1972 developed a new language by inheriting the features of both BCPL and B and adding additional features. He named the language as just C. 

2) Who invented B Language?

Ken Thomson at AT&T Bell Labs developed a language and named it B. Even the B language was found to have some short comings to support development of both business applications and system software. 

3) Who invented BCPL Language?

Basic Combined Programming Language(BCPL) was developed by Martin Richards, Cambridge university. 

4) Why C Language?

C is one of the high level languages. It is a general purpose language, which means it can be used to write programs of any sort. 

5) What are the features of C Langauges?

1. In C one can write programs like that of high level languages as in COBOL, BASIC, FORTRAN etc. as well as it permits very close interaction with the inner workings of the computer. 

2. It is a general purpose programming language. It is usually called system programming language but equally suited to writing a variety of applications. 

3. It supports various data types. 

4. It follows the programming style based on fundamental control flow constructions for structured programming. 

5. Functions may be pre–defined or user defined and they may return values of basic types, structures, unions or pointers. 

6)What are the advantages of c language?

• Easy to write

• Rich set of operators and functions that are built–in

• Support for bit–wise operation

• Flexible use of pointers

• Direct control over the hardware

• Ability to access BIOS/DOS routines

• Interacting using Interrupts

• Ability to write TSR programs

• Ability to create .COM files

• Ability to create library files (.LIB)

• Ability to write interface programs

• Incorporating assembly language in C program

7) What are the disadvantages of c langauge?

• C is considered difficult to learn

• Because of its conciseness, the code can be difficult to follow

• It is not suited to applications that require a lot of report formatting and data file manipulation. 

8) What are the salient features of c languages?

1. The following are the salient features of C language are :

2. C is called a middle level language

3. C supports structured design approach

4. C is extensible

5. C is rich in data types and operators

6. C is portable

9) What is a header file?

Header files provide the definitions and declarations for the library functions. Thus, each header file contains the library functions along with the necessary definitions and declarations. For example, stdio.h, math.h, stdlib.h, string.h etc. 

10) What is character set?

Character set is the set of characters allowed and supported in the programming language. Generally a program is a collection of instructions, which contain groups of characters. Only a limited set of characters is allowed to write instructions in the program. 

11) What is C token?

The smallest individual units of a C program are known as tokens. 

12) List the different types of C tokens?

• Constants

• Identifiers

• Keywords

• Operators

• Special symbols

• Strings 

13) What is a string?

A string is a sequence of characters ending with NUL. It can be treated as a one–dimensional array of characters terminated by a NUL character. 

14) What are qualifiers?

Qualifiers or modifiers are identifiers that may precede the scalar data types (except float) to specify the number of bits used for representing the respective type of data in memory. The qualifiers in C are short, long, signed, and unsigned. 

15) What is a function?

A function is a set of statements to perform a specific task. 

16) What is a constant?

A constant is a value that does not change during the program execution. A constant used in C does not occupy memory. 

17) What are the different types of constants?

There are five types of constants. They are :

1. Integer constants

2. Floating point constants

3. Character constants

4. String literals

5. Enumeration constants 

18) What is variable?

An identifier is used to identify and store some value. If the value of the identifier is changed during the execution of the program, then the identifier is known as variable. 

19) What are the rules for the identifier?

• The first character must be an alphabet or underscore (_)

• Digits may be included in the variable

• The maximum number of characters in a word are 32 (It may vary depending upon the platform)

• No other special characters are allowed.

20) What are global variables?

Global Variables are those, which are required to be acccessed by all the functions defined after their declaration. So, the variables declared before the main {) can be acccessed by all the functions, which follow their declaration. 

21) What is a keyword?

Keywords are those words of C which have predefined meaning assigned by the C language. They form a part of the database required by the C compiler. 

22) What are the different types of c instructions?

There are basically three types of instructions in C are :

1. Type Declaration Instruction

2. Arithmetic Instruction

3. Control Instruction

23) What is an expression?

Expression is defined as a combination of operands and operators to obtain some computation. Operands represent variables or values and The operator tells is what operation to be performed. 

24) What are the types of data files?

There are two types of data files :

• stream oriented or standard data files

• system oriented or low level data files

25) Why C is called a middle level language?

C combines the features of both Assembly Level Languages (Low Level Languages) and Higher Level Languages. For this reason, C is referred to as a Middle Level Language. The feature of ALLs is that of enabling us to develop system level programs and the features of HLLs are those of higher degree of readability and machine independence. 

26) How can variables be characterized?

The variables can be categorized by storage class as well as by data type. The storage class specifies the portion of the program within which the variables are recognized. 

27) Give the rules for variable declaration?

The rules for variable declaration in C are given below :

• A variable name consists of alphabets, digits and the underscore (_) character

• The length of variable should be kept upto 8 characters though your system may allow upto 40 characters

• They must begin with an alphabet

• Some systems also recognize an underscore as the first character

• White space and commas are not allowed

• Any reserved word (keyword) cannot be used as a variable name.

28) What is the purpose of type declarations?

The type declaration allow to create a synonym for other data types. Its syntax is type def type identifier; The declaration type def unsigned long int INTEGER 

29) What is recursion?

C language a function may call another function. When a function calls itself, it is referred to as recursive call and the process is known as recursion. C provides very good facilities for recursion. 

30) What is data types?

Data types refer to the classes of data that can be manipulated by C programs. The three fundamental data types supported by C are character, integer and real type.

Source: Contents are provided by Technicalsymposium Google Group Members. 
Disclaimer: All the above contents are provided by Google Group members. 
Further, this content is not intended to be used for commercial purpose. is not liable/responsible for any copyright issues. Quick Links & Study Notes PDF- Free Download