Software Engineering Interview Questions

Ace your homework & exams now with Quizwiz!

Miss Rate

1 - Hit Rate

What is Inheritance?

C++ allows classes to inherit some of the variables and functions of other classes.

What is C++?

C++ is a computer programming language that is derived from C and includes additional features.

Thread

a sequence of instructions that can be executed concurrently with other such sequences in multithreading environments, while sharing a same address space.

How can we catch all kinds of exceptions in a single catch block?

catch(...){}

QuickSort

/* low --> Starting index, high --> Ending index */ quickSort(arr[], low, high) { if (low < high) { /* pi is partitioning index, arr[pi] is now at right place */ pi = partition(arr, low, high); quickSort(arr, low, pi - 1); // Before pi quickSort(arr, pi + 1, high); // After pi } }

Binary Search Algorithm

1. Compare x with the middle element. 2. If x matches with middle element, we return the mid index. 3. Else If x is greater than the mid element, then x can only lie in right half subarray after the mid element. So we recur for right half. 4. Else (x is smaller) recur for the left half.

What is implicit conversion/coercion in c++?

Implicit conversions are performed when a type (say T) is used in a context where a compatible type (Say F) is expected so that the type T will be promoted to type F.

Mutable Storage Class

In C++, a class object can be kept constant using keyword const. This doesn't allow the data members of the class object to be modified during program execution. But, there are cases when some data members of this constant object must be changed.

Garbage Collection

In Java, and other languages with "garbage collection", you are not required to explicitly de-allocate the memory. The system automatically determines what is garbage and returns it to the available pool of memory. Certainly this makes it easier to learn to program in these languages, but automatic memory management does have performance and memory usage disadvantages.

Set Associative Schemes

In a set associative cache: (Block number) modulo (Number of sets in the cache) All tags of all elements of the set must be searched The total size of the cache in blocks: number of sets * associativity (i.e. n), e.g.,

Preprocessing

In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. It handles preprocessing directives like #include, #define, etc.

Linking

The linker is produces the final compilation output from the object files the compiler produced. This output can be a shared (or dynamic) library or an executable. It links the object files by replacing the undefined references with the correct addresses. These symbols should be defined in other object files or in the libraries. If they are defined in libraries other than the standard library, you need to explicitly pass them to the compiler as an argument so that they can be found and linked.

Stack Memory Allocation

The allocation happens on contiguous blocks of memory. We call it stack memory allocation because the allocation happens in function call stack. Programmer does not have to worry about memory allocation and deallocation of stack variables.

What is the difference between structs and classes?

The member variables of structs are typically public while the member variables of classes are typically private.

Heap Memory Allocation

The memory is allocated during execution of instructions written by programmers. If a programmer does not handle this memory well, memory leak can happen in the program.

What happens if an exception is thrown outside of a try block?

The program will quit abruptly

What is C++ STL?

The standard library contains types and functions that are important extensions to the core C++ language.

What are command line arguments?

The arguments which we pass to the main() function while executing the program are called as command line arguments. The parameters are always strings held in the second argument (below in args) of the function which is array of character pointers. First argument represents the count of arguments (below in count) and updated automatically by operating system.

Compilation

The compilation takes place on the preprocessed files. The compiler parses the pure C++ source code and converts it into assembly code. This in turn calls the assembler that converts the assembly code to machine code(binary) as Object files. These Object files can refer to symbols that are not defined. The compiler won't give an error unless the source code is not well-formed. Syntax errors, failed overload resolution errors, etc occur in this step. Also note these object files can be used as static libraries as well.

What is the 'diamond problem' that occurs with multiple inheritance in C++?

The diamond problem in C++ represents the inability of the programming language to support hybrid inheritance using multiple and hierarchical inheritance.

Smart Pointers

The goal is to create a widget that works just like a regular pointer most of the time, except at the beginning and end of its lifetime. The syntax of how we construct smart pointers is a bit different and we don't need to obsess about how & when it will get deleted (it happens automatically).

What is the C-style character string?

The string is actually a one-dimensional array of characters that is terminated by a null character '\0'.

Default Constructor

These kind of constructors do not have parameters.

Partition for QuickSort

This function takes last element as pivot, places the pivot element at its correct position in sorted array, and places all smaller (smaller than pivot) to left of pivot and all greater elements to right of pivot

Copy Constructor

This type of constructor takes an object as an argument, and is used to create a copy of an existing object of the same class.

Hit Time

Time to access the upper level. Consists of RAM access time + Time to determine hit/miss

Miss Penalty

Time to replace a block in the upper level + Time to deliver the block to the processor

Explain what is multi-threading in C++?

To run two or more programs simultaneously multi-threading is useful. Process-based: It handles the concurrent execution of the program Thread-based: It deals with the concurrent execution of pieces of the same program

Destructor

When an object passes out of scope or is deleted, a destructor destroys the object by deallocating memory and doing other cleanup tasks.

Can the compiler ignore an inline function?

Yes - it is a request not command

Can we call C++ OOPS?

Yes. C++ is an object oriented programming system because it is a language that supports applications such as data binding, polymorphism, inheritance, and more.

Automatic Storage Class

assigns a variable to its default storage type. no keyword is automatic by default.

Types of Smart Pointers

auto_ptr, unique_ptr, scoped_ptr (Boost) , shared_ptr, weak_ptr, scoped_array and shared_array (Boost)

What is realloc() and free()? What is difference between them?

realloc: This function is used to change the size of memory object pointed by address ptr to the size given by size. free: This function is used to deallocate a block of memory that was allocated using malloc(), calloc() or realloc().

Explain the pointer - this.

this is the pointer variable of the compiler which always holds the current active object's address.

Pure Virtual Function

virtual function that must be overridden in a derived class. Indicated by the curious =0 syntax. A pure virtual function can be defined in the class where it is declared pure, but needn't be and usually isn't.

What is a variable?

An object with a name

Differences Between C and C++

C++ supports references C++ is oops C++ has try/catch exception handling C++ uses input/output streams C++ supports both procedural and oop approaches

What is the difference between references and pointers?

1. References are used to refer an existing variable in another name whereas pointers are used to store address of variable. 2. References cannot have a null value assigned but pointer can. 3. A reference variable can be referenced by pass by value whereas a pointer can be referenced but pass by reference. 4. A reference must be initialized on declaration while it is not necessary in case of pointer. 5. A reference shares the same memory address with the original variable but also takes up some space on the stack whereas a pointer has its own memory address and size on the stack.

Block Scope Variable

A Block scope variable is the one that is specified as a block using the C++ that can be declared anywhere within the block.

What is a constructor?

A constructor is a special function within the class that is called by the compiler every time a new object is created, as it initializes the object by assigning a value to it.

What is a friend function?

A function which is not a member of the class but still can access all the member of the class is called so. To make it happen we need to declare within the required class following the keyword 'friend'.

Direct Mapped Cache

A many-to-one map from memory to cache. For each item at the lower level, there is exactly one location in the cache where it might be Cache index = (Memory address) modulo (Number of words in Cache)

What is a namespace?

A namespace is used for resolving the name conflict of the identifier, which is accomplished by placing them under various namespaces. This way, it helps in the logical division of the different codes.

Process

A program in execution.

What is a type?

A structure to memory and a set of operations

What do you mean by internal linking and external linking in c++?

A symbol is said to be linked internally when it can be accessed only from with-in the scope of a single translation unit. By external linking a symbol can be accessed from other translation units as well. This linkage can be controlled by using static and extern keywords.

What is a class template?

A template class is a generic class. The keyword template can be used to define a class template.

What is a token in C++?

A token is a name given to the various functions in C++ programs. Examples of tokens include a keyword, symbol, string literal, identifier, constant, etc.

What is a class?

A user defined data type that has its own member functions and member variables.

malloc()

Allocates the memory of requested size and returns the pointer to the first byte of allocated space.

calloc()

Allocates the space for elements of an array. Initializes the elements to zero and returns a pointer to the memory.

What is an access specifier?

Allows you to define how the members of the class are accessed outside of the scope of the class.

Recursive inline function?

Although you can call an inline function from within itself, the compiler will not generate inline code since the compiler cannot determine the depth of recursion at compile time.

What is an inline function?

An inline function instructs the compiler to insert a copy of the code of that function whenever that function is called. To make a function inline, the keyword "inline" is placed before the name of the function, and function is defined before any calls are made to it.

What is an object?

An instance of a class. They all have member variables and member functions.

Memory Leak

An undesirable state in which a program requests memory but never releases it, which can eventually prevent other programs from running.

Abstract Class

Any class that has pure virtual functions is called "abstract". Objects of abstract types may not be created — only pointers to these objects may be created

External Storage Class

Assigns a variable a reference to a global variable declared outside the given program. They are visible throughout the program and its lifetime is same as the lifetime of the program where it is declared. This visible to all the functions present in the program.

What storage classes are supported in C++?

Auto, Static, Extern, Register, and Mutable

Parametrized Constructor

By passing the appropriate values as arguments, a parameterized constructor provides different values to different objects.

What is polymorphism?

C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function.

What are the different ways of passing parameters to the functions? Which to use when?

Call by value − We send only values to the function as parameters. We choose this if we do not want the actual parameters to be modified with formal parameters but just used. Call by address − We send address of the actual parameters instead of values. We choose this if we do want the actual parameters to be modified with formal parameters. Call by reference − The actual parameters are received with the C++ new reference variables as formal parameters. We choose this if we do want the actual parameters to be modified with formal parameters.

What does the protected access specifier do?

Class members are accessible by child classes and the same class.

What does the public access specifier do?

Class members are accessible throughout the program.

What does the private access specifier do?

Class members are not accessible outside of the class.

What is encapsulation?

Combining data and functions in a class.

What do you mean by translation unit in c++?

Contents of source file Plus contents of files included directly or indirectly Minus source code lines ignored by any conditional pre processing directives ( the lines ignored by #ifdef,#ifndef etc)

Hit

Data is in some block in the upper level

Miss

Data retrieved from a block in the lower level (Block Y)

What do all templated classes need you to write?

Default constructor, copy constructor, destructor, assignment operator

What is operator overloading?

Defining a new job for the existing operator w.r.t the class objects is called as operator overloading.

What is function overloading?

Defining several functions with the same name with unique list of parameters is called as function overloading.

Hit Rate

Fraction of memory accesses in the upper level

free()

Frees or empties the previously allocated memory space.

Translational Lookaside Buffer (TLB)

Fully associative cache to cache the Page Table ---> reduces memory overhead

What is the function of the keyword Volatile?

Helps in declaring that a particular variable is volatile (may change value at different accesses even if it doesn't appear to be modified) and directs the compiler to change the variable externally. Avoids compiler optimization on variable reference.

What is the difference between including with <> vs including ""?

If a header file is included with in < > then the compiler searches for the particular header file only with in the built in include path. If a header file is included with in " ", then the compiler searches for the particular header file first in the current working directory, if not found then in the built in include path

Temporal Locality

If an item is referenced it will tend to be referenced again soon.

Spatial Locality

If an item is referenced, nearby items will tend to be referenced soon

Merge Sort Algorithm

If r > l 1. Find the middle point to divide the array into two halves: middle m = (l+r)/2 2. Call mergeSort for first half: Call mergeSort(arr, l, m) 3. Call mergeSort for second half: Call mergeSort(arr, m+1, r) 4. Merge the two halves sorted in step 2 and 3: Call merge(arr, l, m, r)

Shallow Copy

It allows memory dumping on a bit by bit basis from one object to another. It is achieved by using a copy instructor and an overloading assignment operator

Deep Copy

It allows the copy field, which is done by field from one object to another. It is used for shallow copy purposes.

Is it possible for a C++ program to be compiled without a main function?

It can be compiled but it won't execute

realloc()

It is used to modify the size of previously allocated memory space.

Can we overload a destructor?

No, there are no parameters for a destructor and that's it

Is there a String primitive data type in C++?

No, we have a class from stl

What are operators?

Operators are specific operands in C++ that are used to perform specific operations to obtain a result. The different types of operators available for C++ are Assignment Operator, Compound Assignment Operator, Arithmetic Operator, Increment Operator and so on.

Explain what is pre-processor in C++?

Pre-processors are the directives, which give instruction to the compiler to pre-process the information before actual compilation starts.

Deadlock

Processes competing for resources --> progress of system is suspended.

Improve Cache Performance

Reduce Miss Rate Increase Block Size Make Block Usage More Efficient Reduce Miss Penalty Faster memory Multilevel Cache

Types of Garbage Collection

Reference counting, stop and copy, mark and sweep

Register Storage Class

Register storage assigns a variable's storage in the CPU registers rather than primary memory. It has its lifetime and visibility same as automatic variable. So only those variables which requires fast access should be made register.

What is the scope resolution operator?

Resolve the scope of global variables. To associate function definition to a class if the function is defined outside the class. Ex return type class name::function name or vector<>::iterator

Memory Technologies

SRAM -> DRAM -> SSD -> HDD

What is an abstraction?

Show only necessary details for an object, not the inner details of an object.

Virtual Keyword

Some of these functions are marked virtual, which means that when they are redefined by a derived class, this new definition will be used, even for pointers to base class objects.

Static Storage Class

Static storage class ensures a variable has the visibility mode of a local variable but lifetime of an external variable. It can be used only within the function where it is declared but destroyed only after the program execution has finished. When a function is called, the variable defined as static inside the function retains its previous value and operates on it. This is mostly used to save values in a recursive function.

What is a storage class?

Storage class specifies the life or scope of symbols such as variable or functions.


Related study sets

PARTNERSHIPS CHAPTER 1: General Provisions

View Set

Psychology - Unit test #1 - Chap 2

View Set

Government and Economics Unit 7 Quiz 2: Business and You

View Set

Medical Terminology (Lesson One) (JJ Medicine)

View Set

NUR 304 Chapter 48 Concepts of Care for Patients with Noninflammatory Intestinal Conditions

View Set

Chapter 14 BAC 338 Market Research

View Set

Chapter 17.3: Ming and Qing Dynasties

View Set